extend webpack nextjs

extend webpack nextjs

In order to extend our usage of webpack in #NextJS, you can define a function that extends its config inside next.config.js. The webpack function is executed twice, once for the server and once for the client. #javascript #reactjs #programming

Copy Snippet
module.exports = {
  webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => {
    // Note: we provide webpack above so you should not `require` it
    // Perform customizations to webpack config
    // Important: return the modified config
    config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//))
    return config
  },
  webpackDevMiddleware: config => {
    // Perform customizations to webpack dev middleware config
    // Important: return the modified config
    return config
  },
}