Skip to solution
mediumFrontend

What is next.config.js in Next.js and what are common configurations?

596 views
01

Understand the problem

The framework configuration file.

nextjsnext-configconfigurationbuild
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

next.config.js (or .ts/.mjs) configures the build and runtime: redirects(), rewrites(), headers(), images (remote patterns/loaders), output mode, experimental flags, env, transpilePackages, and webpack/turbopack tweaks. It's evaluated at build/start, not per request.

Solution ready — 2 min read

Classified // press E to declassify

04

Read the code

A typical next.config
// next.config.ts
import type { NextConfig } from 'next';
const config: NextConfig = {
  output: 'standalone',
  images: { remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }] },
  async redirects() { return [{ source: '/old', destination: '/new', permanent: true }]; },
  async headers() { return [{ source: '/(.*)', headers: [{ key: 'X-Frame-Options', value: 'DENY' }] }]; },
  experimental: { optimizePackageImports: ['lodash'] },
};
export default config;
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 47 of 95 decoded in the Next.js track. One more won't hurt.

Back to track