针对多入口js文件,当引入多个相同的自定义模块或者第三方库的时候,提取公共的js代码,减少代码冗余,提高页面加载速度
module.exports = {
entry: {
index: './src/index.js',
pageC: './src/pageC.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name][hash:5].bundle.js',
chunkFilename: '[name][hash:5].js'
},
optimization:{
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'all',
minSize: 1,
minChunks: 2,
priority: 1
},
vender: {
name: 'vender',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'all'
}
}
}
},
module: {
rules: [
{
...
}
]
},
plugins: [
...
],
mode: 'development'
}