boilerplate
boilerplate copied to clipboard
rpg-next: split babel out into separate chunk
module.exports = {
webpack: (config, options) => {
if (!options.isServer && !options.dev) {
config.optimization.splitChunks.cacheGroups.babel = {
chunks: 'all',
name: 'babel',
test: /[\\/]node_modules[\\/](@babel|regenerator-runtime)[\\/]/
};
}
return config;
}
);```
Using the following config, I was able to reduce the parsed bundle size of a project from:
- before: 885.56 KB (294.36 KB gzipped)
- after: 357.3 KB (108.86 KB gzipped)
module.exports = {
webpack: (config, options) => {
if (!options.isServer && !options.dev) {
config.optimization.splitChunks.cacheGroups = {
babel: {
chunks: 'all',
name: 'babel',
priority: 2,
test: /[\\/]node_modules[\\/](@babel|regenerator-runtime)[\\/]/
},
common: {
maxInitialRequests: 5,
name: 'common'
},
react: {
chunks: 'all',
name: 'react',
priority: 2,
test: /[\\/]node_modules[\\/](react|react-dom)[\\/]/
},
vendor: {
chunks: 'all',
enforce: true,
name: 'vendor',
priority: 1,
test: /node_modules/
}
};
}
return config;
}
};
This overwrites Next.js' config.optimization.splitChunks.cacheGroups instead of merging, but this works for the project I'm working on.