1. // initial 对于异步导入的文件不处理
    2. // async 对异步导入的文件处理
    3. // all 全部chunk
    4. optimization: {
    5. chunks: 'all',
    6. cacheGroups: {
    7. // 第三方模块
    8. vendor: {
    9. name: 'vendor', // chunk的名字
    10. priority: 1, // 优先级
    11. test: /node_modules/,
    12. minSize: 0, //公共模块限制大小
    13. minChunks: 1 // 最少复用多少次
    14. },
    15. // 公共模块
    16. common: {
    17. name: 'common',
    18. priorrity: 0,
    19. minSize: 0, // 公共模块限制大小
    20. minChunks: 2 // 最少复用多少次
    21. }
    22. }
    23. }

    然后在chunks中可添加

    const config = {
    entry:{
    index:path.join(srcPath,’index.js’),
    other:path.join(srcPath,’other.js’)
    },
    plugins:[
    new HtmlWebpackPlugin({
    template:path.join(srcPath,’index.html’),
    filename:’index.html’,
    // chunks 表示该页面要引用哪些chunk 即上面的 index 和 other
    chunks:[‘index’]
    }),
    new HtmlWebpackPlugin({
    template:path.join(srcPath,’other.html’),
    filename:’other.html’,
    chunks:[‘other’]
    })
    ]
    }