webpack配置提取公共程式碼
阿新 • • 發佈:2018-10-31
公共程式碼提取功能是針對多入口檔案的;
背景:在pageA.js和pageB.js中分別引用subPageA.js和subPageB.js
webpack.config.js檔案:
1 var path = require('path') 2 module.exports = { 3 entry:{ 4 pageA:'./src/pageA.js', 5 pageB:'./src/pageB.js' 6 }, 7 output: { 8 filename: "[name].js", 9 path:path.resolve(__dirname,'./dist')10 }, 11 optimization: { 12 splitChunks:{ 13 cacheGroups: { 14 vender:{ 15 test:/node_modules/, 16 chunks:'initial', 17 name:'vender', 18 priority:10 19 }, 20 utils:{21 chunks:'initial', 22 name:'utils', 23 minSize:0 24 } 25 } 26 } 27 } 28 }