Deployment Patterns for Next.js
Documentation lookup
Check Next.js docs via llms.txt for latest deployment guidance.
Deployment options overview
Vercel (recommended)
- •Zero-config deployment from Git
- •Automatic preview deployments on PRs
- •Edge/Serverless/ISR support built-in
- •Analytics and Speed Insights
Docker / Self-hosted
- •Use
output: 'standalone'in next.config.ts - •Multi-stage Dockerfile for minimal image
- •Need to handle ISR/caching yourself
Static Export
- •
output: 'export'for static HTML - •No server-side features (no SSR, no API routes, no ISR)
- •Deploy to any static host (S3, Cloudflare Pages, GitHub Pages)
Environment variables
- •Build-time: available during
next build(baked into the bundle) - •Runtime: available during
next start(server-only) - •
NEXT_PUBLIC_prefix: exposed to client-side JavaScript - •Never put secrets in
NEXT_PUBLIC_variables
Build output
bash
npm run build # .next/ # static/ # Static assets (CSS, JS chunks) # server/ # Server-side code # cache/ # Data cache, page cache
Edge Runtime
- •Subset of Node.js APIs
- •Faster cold starts, global distribution
- •Use
export const runtime = 'edge'in route handlers/pages - •Limitations: no fs, no native Node modules, limited crypto
CI/CD patterns
- •Cache .next/cache between builds for faster builds
- •Run
npx tsc --noEmitbefore build for type checking - •Run tests before deploy
- •Use preview deployments for PR review
References
- •Vercel config:
references/vercel-config.md - •Docker setup:
references/docker-setup.md