Deployment
Learn how to deploy your documentation site to production.
Vercel (Recommended)
Vercel is the easiest way to deploy Next.js applications.
One-Click Deploy
Manual Deploy
- Push your code to GitHub
- Go to vercel.com
- Import your repository
- Vercel will automatically detect Next.js and configure the build
Environment Variables
If you have environment variables, add them in the Vercel dashboard:
- Go to Project Settings → Environment Variables
- Add your variables for Production, Preview, and Development
Netlify
Deploy via Git
- Push your code to GitHub/GitLab/Bitbucket
- Go to netlify.com
- Click “New site from Git”
- Select your repository
- Configure build settings:
- Build command:
npm run build - Publish directory:
.next
- Build command:
netlify.toml
Create a netlify.toml file in the project root:
[build]
command = "npm run build"
publish = ".next"
[[plugins]]
package = "@netlify/plugin-nextjs"Static Export
If you need a fully static site (no server required):
Configure Next.js
Edit next.config.ts:
import nextra from "nextra";
const withNextra = nextra({
defaultShowCopyCode: true,
});
export default withNextra({
reactStrictMode: true,
output: "export", // Enable static export
images: {
unoptimized: true, // Required for static export
},
});Build Static Files
npm run buildThe static files will be in the out/ directory.
Deploy Anywhere
Upload the out/ directory to any static hosting:
- GitHub Pages
- Cloudflare Pages
- AWS S3 + CloudFront
- Any web server
Docker
Dockerfile
Create a Dockerfile:
FROM node:18-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY . .
RUN npm run build
FROM node:18-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/public ./public
EXPOSE 3000
CMD ["npm", "start"]Build and Run
docker build -t my-docs .
docker run -p 3000:3000 my-docsGitHub Pages
Configure for GitHub Pages
-
Enable static export in
next.config.ts(see above) -
Create
.github/workflows/deploy.yml:
name: Deploy to GitHub Pages
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "18"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./out- Enable GitHub Pages in repository settings, selecting “gh-pages” branch
Custom Domain
Vercel
- Go to Project Settings → Domains
- Add your custom domain
- Configure DNS as instructed
Other Platforms
Add a CNAME file to the public/ directory:
docs.your-domain.comThen configure your DNS to point to your hosting provider.
Build Scripts
| Command | Description |
|---|---|
npm run dev | Start development server |
npm run build | Build for production |
npm run start | Start production server |
npm run lint | Run ESLint |
Last updated on