webpack配置提取公共代码

公共代码提取功能是针对多入口文件的;

  背景:在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 }

 

posted @ 2018-10-31 12:00  前端极客  阅读(1071)  评论(0编辑  收藏  举报