▲ Next.js Beginner

What is the next.config.js file?

Answer

The next.config.js (or next.config.ts for TypeScript) file configures Next.js behavior. It's a regular Node.js module that exports a configuration object. Key configuration options: const nextConfig = { // Redirect rules redirects: async () => [{ source: "/old-path", destination: "/new-path", permanent: true }], // URL rewriting rewrites: async () => [{ source: "/api/:path*", destination: "https://backend.com/:path*" }], // Image domains images: { remotePatterns: [{ hostname: "images.unsplash.com" }] }, // Custom headers headers: async () => [{ source: "/(.*)", headers: [{ key: "X-Content-Type-Options", value: "nosniff" }] }], // Environment variables (build-time) env: { NEXT_PUBLIC_API_URL: process.env.NEXT_PUBLIC_API_URL }, // i18n internationalization i18n: { locales: ["en", "fr", "es"], defaultLocale: "en" }, // React strict mode reactStrictMode: true, // Experimental features experimental: { serverActions: { allowedOrigins: ["my-proxy.com"] } }, // Webpack customization webpack: (config, { buildId, dev }) => { config.module.rules.push(...); return config; }, // Output modes output: "standalone", // for Docker deployments // Transpile packages transpilePackages: ["@company/ui-lib"] }; export default nextConfig;.