Next.js
Beginner
1 min read
Next.js Configuration with next.config.js
Example
// next.config.js
/** @type {import('next').NextConfig} */
const nextConfig = {
// Enable React strict mode for catching bugs early
reactStrictMode: true,
// Allow next/image to load images from external domains
images: {
remotePatterns: [
{
protocol: 'https',
hostname: 'images.unsplash.com',
},
{
protocol: 'https',
hostname: 'cdn.example.com',
port: '',
pathname: '/uploads/**',
},
],
},
// Permanent redirects
async redirects() {
return [
{
source: '/old-blog/:slug',
destination: '/blog/:slug',
permanent: true, // 308 status
},
];
},
// Rewrites (proxy without URL change)
async rewrites() {
return [
{
source: '/api/v1/:path*',
destination: 'https://external-api.com/:path*',
},
];
},
// Output mode for Docker deployment
output: 'standalone',
};
module.exports = nextConfig;
Related Resources
Next.js Reference
Complete tag & property list
Next.js How-To Guides
Step-by-step practical guides
Next.js Exercises
Practice what you've learned
More in Next.js