boilerplate icon indicating copy to clipboard operation
boilerplate copied to clipboard

rpg-next: split babel out into separate chunk

Open chadfurman opened this issue 7 years ago • 1 comments

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;
  }
);```

chadfurman avatar Jun 12 '19 14:06 chadfurman

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.

ptb avatar Jun 12 '19 17:06 ptb