When doing code-follow webpack4 Chinese network npm run build
when 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 to generate a name for the vendors~another~app.bundle.js
file, I want to use my name may be.
optimization: {
splitChunks: {
chunks: 'all',
name:'common'
}
},
After npm run build, as FIG.
The file directory dist:
Examples Links: Code separation / demo13_splitting-code /