Capítulo 194 de 456
Central configuration file for a Next.js project, loaded by the Next.js server and build phases (not included in the browser bundle). Supports plain object, function, or async function exports, and can target specific build phases.
.cjs/.cts não são suportados. .mjs para ESM, .ts para TypeScript.(phase, { defaultConfig }) => nextConfig, permitindo lógica condicional por fase (inclusive async).PHASE_DEVELOPMENT_SERVER), importável de next/constants.next/experimental/testing/server) que executa headers, redirects e rewrites do config isoladamente.// @ts-check
const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')
module.exports = (phase, { defaultConfig }) => {
if (phase === PHASE_DEVELOPMENT_SERVER) {
return { /* development only config options here */ }
}
return { /* config options for all phases except development here */ }
}
import { getRedirectUrl, unstable_getResponseFromNextConfig } from 'next/experimental/testing/server'
const response = await unstable_getResponseFromNextConfig({
url: 'https://nextjs.org/test',
nextConfig: {
async redirects() {
return [{ source: '/test', destination: '/test2', permanent: false }]
},
},
})
expect(response.status).toEqual(307)
expect(getRedirectUrl(response)).toEqual('https://nextjs.org/test2')
redirects sem subir o servidor completo.next.config.js não passa por Webpack/Babel, então não é transpilado.next.config.js, ignorando rotas de proxy e filesystem — o resultado real pode diferir.next.config.ts é suportado nativamente para tipagem.unstable_getResponseFromNextConfig.