Reputation: 518
I've got my webpack optimization configured as follows:
optimization: {
runtimeChunk: 'single',
minimize: false,
splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
minSize: 0,
cacheGroups: {
config: {
test: /[\\/]app[\\/]js[\\/]config[\\/]/,
minSize: 0
},
vendors: {
test: /[\\/]node_modules[\\/]/,
name(module) {
// get the name. E.g. node_modules/packageName/not/this/part.js
// or node_modules/packageName
const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];
// npm package names are URL-safe, but some servers don't like @ symbols
return `npm.${packageName.replace('@', '')}`;
},
}
},
},
},
This work perfectly and generates all the bundles I want. BUT, I don't want the config bundle to be minified. All the other bundles should be minified though. So far I've only found a global setting, minimize: true/false. I there another, more granular way of setting this?
Upvotes: 0
Views: 1068
Reputation: 4987
Check the documentation about optimization.minimizer setting and chunkFilter
option. You should set a name for config
chunk. And add something like this to your optimization
settings:
minimizer: [
new TerserPlugin({
chunkFilter: (chunk) => {
if (chunk.name === 'CONFIG CHUNK NAME') {
return false;
}
return true;
},
}),
],
Note that you need to require the plugin: const TerserPlugin = require('terser-webpack-plugin');
.
Upvotes: 2