我有一个使用 webpack2 构建的 react 项目,但是构建的块文件都过大了,总大小超过了 10M!这是我的配置和日志输出的一部分。
module.exports = {
entry: {
app: appConf.entry
},
output: {
path: appConf.buildRoot,
publicPath: appConf.assetsPublicPath,
filename: assetsPath('js/[name].[chunkhash].js'),
chunkFilename: assetsPath('js/[id].[chunkhash].js')
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function(module, count) {
// any required modules inside node_modules are extracted to vendor
return (module.resource && /\.js$/.test(module.resource) && module.resource.indexOf(path.join(__dirname, '../../node_modules')) === 0);
}
}),
// extract webpack runtime and module manifest to its own file in order to
// prevent vendor hash from being updated whenever app bundle is updated
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest',
chunks: ['vendor']
})
]
};