Webpack-dev-server 在每次更改后发出所有块 [英] Webpack-dev-server emits all chunks after every change
问题描述
我刚刚为我们的开发环境实现了热重载.我的 javascript 被分解成很多块.每次我对文件进行更改时,所有块都会重新提交.我正在运行 webpack-dev-server.
I just implemented hot-reload'ing for our dev environment. My javascript is broken up into a lot of chunks. Every time I make a change to a file all of the chunks get re-submitted. I'm running webpack-dev-server.
这是一个例子:
Hash: 83298e5f7612c91d96ee
Version: webpack 1.13.1
Time: 2417ms
chunk {0} static/js/music/bundle.js (bundle) 1.87 MB
+ 591 hidden modules
chunk {1} static/js/music/1.js 609 kB {0}
+ 103 hidden modules
chunk {2} static/js/music/2.js 179 kB {0}
+ 42 hidden modules
chunk {3} static/js/music/3.js 186 kB {0}
+ 44 hidden modules
chunk {4} static/js/music/4.js 85.5 kB {0}
+ 12 hidden modules
chunk {5} static/js/music/5.js 35.5 kB {0}
+ 9 hidden modules
chunk {6} static/js/music/6.js 835 kB {0}
+ 163 hidden modules
chunk {7} static/js/music/7.js 817 kB {0}
+ 157 hidden modules
chunk {8} static/js/music/8.js 953 kB {0}
+ 189 hidden modules
chunk {9} static/js/music/9.js 11.6 kB {0} {16} {21}
[901] ./js/base/mychange.jsx 9.24 kB {9} [built]
+ 1 hidden modules
chunk {10} static/js/music/bundle2.js (bundle2) 1.87 MB
+ 590 hidden modules
chunk {11} static/js/music/11.js 1.23 MB {10}
+ 216 hidden modules
chunk {12} static/js/music/bundle3.js (bundle3) 1.87 MB
+ 590 hidden modules
chunk {13} static/js/music/13.js 1.23 MB {12}
+ 215 hidden modules
chunk {14} static/js/music/14.js 873 kB {12}
+ 160 hidden modules
chunk {15} static/js/music/15.js 1.22 MB {12}
+ 212 hidden modules
chunk {16} static/js/music/bundle4.js (bundle4) 1.87 MB
+ 590 hidden modules
chunk {17} static/js/music/17.js 566 kB {16}
+ 93 hidden modules
chunk {18} static/js/music/18.js 474 kB {16}
+ 33 hidden modules
chunk {19} static/js/music/19.js 486 kB {16}
+ 33 hidden modules
chunk {20} static/js/music/20.js 955 kB {16}
+ 190 hidden modules
webpack: bundle is now VALID.
如您所见,实际上只构建了 mychange.jsx 文件.但是,其余的还是发出了,整个变化用了 2.4 秒.
As you can see, only the mychange.jsx file was actually built. However, the rest were still emitted, and the change took a whole 2.4 seconds.
这是为什么?我是否缺少 webpack 的一些设置?
Why is this? Am I missing some setting for webpack?
当我运行 webpack --watch 并进行更改时,只会发出正确的块.所以,我知道它一定是我遗漏的一些小东西.
When I run webpack --watch and make a change, only the proper chunk gets emitted. So, I know it must be something small I'm missing.
推荐答案
尝试在 stats 对象中添加 chunks:false
解决了这个问题.参考:https://webpack.github.io/docs/node.js-api.html
Try to add chunks:false
in the stats object solves this. ref: https://webpack.github.io/docs/node.js-api.html
devServer: {
stats: { chunks:false }
}
这里是相关代码.看起来可接受的预设值是:none、errors-only、minimum、normal、verbose,否则您可以指定自己的对象:
Here's the relevant code. Looks like the acceptable preset values are: none, errors-only, minimal, normal, verbose and otherwise you can specify your own object:
{
hash: false,
version: false,
timings: false,
assets: false,
chunks: false,
modules: false,
reasons: false,
children: false,
source: false,
errors: false,
errorDetails: false,
warnings: false,
publicPath: false
}
这篇关于Webpack-dev-server 在每次更改后发出所有块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!