AgentSkillsCN

deployment

为Next.js应用制定部署模式。涵盖Vercel部署、独立输出的Docker容器、基于Node.js的自托管方案、Edge Runtime运行时、环境变量、构建输出分析,以及CI/CD部署模式。

SKILL.md
--- frontmatter
name: deployment
description: "Deployment patterns for Next.js applications. Covers Vercel deployment, Docker with standalone output, self-hosting with Node.js, Edge Runtime, environment variables, build output analysis, and CI/CD patterns."
license: MIT
metadata:
  author: Balazs Barta
  version: "0.1.0"

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 --noEmit before build for type checking
  • Run tests before deploy
  • Use preview deployments for PR review

References