Webpack 4 migration CommonsChunkPlugin

前端 未结 4 946
傲寒
傲寒 2020-12-02 11:16

I need help migrating the following code from webpack 3 to 4.

new webpack.optimize.CommonsChunkPlugin({
    minChunks: module => module.context &&         


        
4条回答
  •  难免孤独
    2020-12-02 11:58

    Please note that I corrected the issue by changing this in my webpack.common.js:

      plugins: [
        new webpack.optimize.CommonsChunkPlugin({
          name: ['vendor']
        })
        ]
    

    To this:

      optimization: {
          runtimeChunk: "single", // enable "runtime" chunk
          splitChunks: {
              cacheGroups: {
                  vendor: {
                      test: /[\\/]node_modules[\\/]/,
                      name: "vendor",
                      chunks: "all"
                  }
              }
          }
      },
    

提交回复
热议问题