公共代码提取功能是针对多入口文件的;
背景:在pageA.js和pageB.js中分别引用subPageA.js和subPageB.js
webpack.config.js文件:
var path = require('path')
module.exports = {
entry:{
pageA:'./src/pageA.js',
pageB:'./src/pageB.js'
},
output: {
filename: "[name].js",
path:path.resolve(__dirname,'./dist')
},
optimization: {
splitChunks:{
cacheGroups: {
vender:{
test:/node_modules/,
chunks:'initial',
name:'vender',
priority:10
},
utils:{
chunks:'initial',
name:'utils',
minSize:0
}
}
}
}
}