Here is the output from bundle-analyzer:

As you can see packages as react-dom, jquery and mobx are both in shell bundle and vendor bundle. Is it possible to put them only in vendor bundle?
UPDATE Here is config file:
entry: {
shell: './src/shell.ts',
vendor: [
'jquery',
'react',
'react-dom',
'react-router',
'mobx',
'mobx-react',
'toastr',
'styled-components',
],
},
output: {
path: __dirname + '/dist',
filename: '[name]bundle.js?[hash:8]',
publicPath: '/',
},
devtool: PROD ? false : 'source-map',
resolve: {
extensions: ['.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.json'],
modules: ['node_modules'],
},
optimization: {
minimize: !!PROD,
},
plugins: [
new CleanWebpackPlugin(['dist']),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
new ExtractTextPlugin('[name].css?[hash:8]', {
allChunks: true,
disable: !PROD,
}),
new HtmlWebpackPlugin({
chunksSortMode: 'dependency',
template: './src/index.tpl.html',
}),
new BundleAnalyzerPlugin(),
],
You can split all your vendor code comming from the node_modules folder into a single vender bundle file using splitChunks optimization webpack setting.
Firstly, remove vendor form your entry.
Then, add the below code to your config file:
optimization: {
splitChunks: {
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/ ,
name: 'vendor' ,
chunks: 'all' ,
enforce: true ,
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With