Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChu

When doing code-follow webpack4 Chinese network npm run buildwhen an error occurs,


Error: webpack.optimize.CommonsChunkPlugin has been removed, please use config.optimization.splitChunks instead.

Quguan own network looked, https://webpack.js.org/guides/code-splitting/
is added.

  const path = require('path');

  module.exports = {
    mode: 'development',
    entry: {
      index: './src/index.js',
      another: './src/another-module.js'
    },
    output: {
      filename: '[name].bundle.js',
      path: path.resolve(__dirname, 'dist')
    },
+   optimization: {
+     splitChunks: {
+       chunks: 'all'
+     }
+   }
  };

Results are as follows:Here Insert Picture Description

Here to generate a name for the vendors~another~app.bundle.jsfile, I want to use my name may be.

 optimization: {
        splitChunks: {
            chunks: 'all',
            name:'common'
        }
    },

After npm run build, as FIG.

Here Insert Picture Description

The file directory dist:
Here Insert Picture Description
Examples Links: Code separation / demo13_splitting-code /

Published 56 original articles · won praise 24 · views 30000 +

Guess you like

Origin blog.csdn.net/u014196765/article/details/99563779