Webpack 4 migration CommonsChunkPlugin

前端 未结 4 948
傲寒
傲寒 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:40

    This took me a while to figure out, but the key realization for me was that the chunks argument in webpack 4 now takes a function, which allows you to only include a specific entry. I'm assuming this is a recent change, because at the time of posting it wasn't in the official documentation.

    splitChunks: {
      cacheGroups: {
        vendor: {
          name: 'vendor',
          chunks: chunk => chunk.name == 'main',
          reuseExistingChunk: true,
          priority: 1,
          test: module =>
            /[\\/]node_modules[\\/]/.test(module.context),
          minChunks: 1,
          minSize: 0,
        },
      },
    },
    

提交回复
热议问题