我刚为我们的开发环境实现了热重载。我的javascript被分解成很多块。每次我对文件进行更改时,都会重新提交所有块。我正在运行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秒。
这是为什么?我错过了webpack的一些设置吗?
当我运行webpack --watch并进行更改时,只会发出正确的块。所以,我知道它一定是我想念的小事。
答案 0 :(得分:2)
尝试在stats对象中添加chunks:false
解决此问题。参考:https://webpack.github.io/docs/node.js-api.html
devServer: {
stats: { chunks:false }
}
Here's the relevant code。看起来可接受的预设值是:none,errors-only,minimal,normal,verbose,否则你可以指定自己的对象:
{
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
}