Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpg-next: split babel out into separate chunk #59

Open
chadfurman opened this issue Jun 12, 2019 · 1 comment
Open

rpg-next: split babel out into separate chunk #59

chadfurman opened this issue Jun 12, 2019 · 1 comment

Comments

@chadfurman
Copy link

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 chadfurman changed the title rpg-next: split babel out from main bundle rpg-next: split babel out into separate chunk Jun 12, 2019
@ptb
Copy link

ptb commented Jun 12, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants