Capítulo 426 de 456
Escape hatch to extend Next.js's webpack config directly via a function in next.config.js. Not covered by semver, so changes here carry upgrade risk.
webpack(config, options): function that receives and must return the modified webpack config; executed three times (twice for server: nodejs/edge, once for client).options.isServer: true for server compilation, false for client.options.nextRuntime: "edge" or "nodejs" for server compilation, undefined for client. isServer is true when nextRuntime is either "edge" or "nodejs".options.buildId: unique identifier for the build.options.dev: true in development compilation.options.defaultLoaders.babel: default babel-loader config, useful for chaining custom loaders after it.module.exports = {
webpack: (
config,
{ buildId, dev, isServer, defaultLoaders, nextRuntime, webpack }
) => {
// Important: return the modified config
return config
},
}
config modificado, senão o build quebra.@next/mdx, @next/bundle-analyzer) antes de escrever config webpack customizada.