LoginSignup
11
12

More than 5 years have passed since last update.

#webpack chunkファイル名にbuildの度に現在時刻をいれる

Posted at

キャッシュされたものが利用されないようwebpackが生成するchunkファイル名にbuildの度に現在時刻をいれた時のメモ

webpack.config.jsoutput.chunkFilenameに現在時刻を含める

webpack.config.js
module.exports = {
    entry : {
        entry : "./entry.js",
    },
    output : {
        path: __dirname,
        filename: "bundle.js",
        chunkFilename: "[id].bundle.js?" + (+new Date),
        publicPath: "/js/"
    }
}
  • (+new Date)が現在時刻

HTMLに出力後は次のようになる

HTML
<script type="text/javascript" charset="utf-8" async="" src="/js/0.bundle.js?1444118019225"></script>
  • [hash]でも十分かもしれない。
    例えば、chunkFilename: "[id].bundle.js?[hash]",
  • QUERY_STRINGではなくファイル名とする方法も良いかもしれない。
    例えば、chunkFilename: "[id].[hash].js",

参考

11
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
12