Next.js は複数のデプロイメントターゲットをサポートしており、その一部は output 設定で制御されます。正しい選択は、Node サーバー、コンテナ、または純粋な静的ホスティングが必要かどうかによって異なります。
ビルド出力モード
js
// next.config.js
module. = {
};
Node.js サーバーを実行するため、すべて が利用できます:SSR、ISR、Server Actions、Route Handlers、画像最適化、ミドルウェア。これは Vercel(Next.js の開発元、ゼロコンフィグ)や Node ホストが使用するものです。
# Next traces only the needed files into .next/standalone → a tiny, self-contained server
COPY --from=builder /app/.next/standalone ./
CMD ["node", "server.js"]
standalone は実際に使用される依存関係のみを含む最小限のフォルダを生成し、AWS、GCP、独自のサーバーなどで小さな Docker イメージに最適です。すべてのサーバー機能を維持します。
next build → out/ (plain HTML/CSS/JS, deployable to any static host: S3, GitHub Pages, Netlify CDN)
静的エクスポートは最も安価でシンプルなホスティングを提供しますが、サーバー機能を無効にします:SSR なし、ISR なし、Route Handlers なし、Server Actions なし、オンザフライの画像最適化なし。完全に静的なサイトにのみ適しています。
Need SSR/ISR/Server Actions, want zero-config → Vercel (or a Node host) — default output
Want containers / self-host with full features → output: "standalone" + Docker
Purely static content (docs, marketing) → output: "export" → any static CDN
- Runtime choice (Edge vs Node) affects where functions run
- Self-hosting ISR/caching needs persistent storage or a shared cache
- Image optimization on non-Vercel hosts may need a custom loader
デプロイメントは万能ではありません。output モードは Next.js のどの機能が有効かを決定します。
デフォルト/Node 出力はすべてのサーバー機能を維持し、standalone はそれらを Docker/セルフホスティング用にパッケージ化し、export はすべてのサーバー機能を純粋な静的ホスティングと交換することを理解していれば、ビルドをインフラストラクチャに合わせることができます—また、output: "export" が SSR/ISR/Server Actions を静かに破壊する罠を避けられます。