nextjs-webpack-override

1.0.1 • Public • Published

Next.js Webpack Config Override

Get total control over Next.js Webpack configurations

Commitizen friendly Version

Downloads License License

Installation

npm

npm install nextjs-webpack-override --save

Yarn

yarn add nextjs-webpack-override

Getting Started

This project allows developers to take full control of Webpack configurations in Next.js projects. Next only gives limited access to webpack control - often leaving developers limited when trying to perform advanced re-configurations.

// standard next.js config
const NextJsWebpackOverride = require('nextjs-webpack-override');
 
module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    config.plugins.push(
      new NextJsWebpackOverride({
        // any standard webpack options that are usually inaccessible
        optimization: {
          runtimeChunk: 'single',
          splitChunks: {
            chunks: 'all',
            maxInitialRequests: Infinity,
            minSize: 0,
            cacheGroups: {
              vendor: {
                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('@', '')}`;
                },
              },
            },
          },
        },
      })
    );
    return config;
  },
  webpackDevMiddleware: (config) => {
    return config;~~~~
  },
};

Dependents (1)

Package Sidebar

Install

npm i nextjs-webpack-override

Weekly Downloads

217

Version

1.0.1

License

MIT

Unpacked Size

6.83 kB

Total Files

5

Last publish

Collaborators

  • zackljackson