Build & Deploy
Local builds, production deployment, and Vercel configuration
Plainform is optimized for deployment on Vercel with Next.js 16 features including Cache Components mode and Partial Prerendering.
Local Build
Test production builds locally before deploying:
npm run build
npm run startpnpm build
pnpm startyarn build
yarn startBuild process:
- Validates environment variables (via
env.ts) - Compiles TypeScript
- Generates Prisma client
- Processes MDX content (Fumadocs)
- Optimizes images and assets
- Creates production bundles with Turbopack
- Generates sitemap (postbuild script)
Build time: 30-90 seconds depending on content size and machine specs.
Build Output
Route (app) Size First Load JS
┌ ○ / 5.2 kB 120 kB
├ ○ /blog 2.1 kB 115 kB
├ ◐ /docs 1.8 kB 112 kB
├ ● /docs/[...slug] 3.4 kB 118 kB
└ ○ /sign-in 4.2 kB 119 kB
○ (Static) Prerendered at build time
● (SSG) Prerendered with getStaticProps
◐ (Partial) Partial Prerendering (static shell + dynamic streaming)Route indicators:
○Static - Fully prerendered at build time●SSG - Static with data fetching◐Partial - Static shell with dynamic content (Next.js 16)
Most routes use Partial Prerendering (◐) for optimal performance - static shell renders instantly while dynamic content streams.
Environment Variables
Required Variables
All environment variables are validated using Zod schemas in env.ts:
| Category | Variables | Required |
|---|---|---|
| Site | SITE_URL, NEXT_PUBLIC_SITE_URL | ✅ |
| Clerk | CLERK_SECRET_KEY, NEXT_PUBLIC_CLERK_* | ✅ |
| Stripe | STRIPE_SECRET_KEY, STRIPE_WEBHOOK_SECRET | ✅ |
| Database | DATABASE_URL, DIRECT_URL | ✅ |
| AWS S3 | AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_S3_* | ✅ |
| Resend | RESEND_API_KEY | ✅ |
| Mailchimp | MAILCHIMP_API_KEY, MAILCHIMP_AUDIENCE_ID | ✅ |
| PostHog | NEXT_PUBLIC_POSTHOG_KEY, NEXT_PUBLIC_POSTHOG_HOST | ✅ |
See Environment Variables for detailed configuration guide.
Local vs Production
Local development (.env):
- Use test API keys (Stripe test mode, Clerk development)
- Local database connection
http://localhost:3000URLs
Production (Vercel):
- Live API keys
- Production database (Supabase)
- Custom domain URLs
- Webhook secrets for live mode
Deploy to Vercel
Connect Repository
- Go to vercel.com
- Click "Add New Project"
- Import your Git repository (GitHub/GitLab/Bitbucket)
- Select the repository
Configure Project
Framework Preset: Next.js (auto-detected)
Build Settings:
- Build Command:
npm run build(default) - Output Directory:
.next(default) - Install Command:
npm install(default)
Root Directory: Leave as . (project root)
Vercel automatically detects Next.js 16 and uses Turbopack for builds.
Add Environment Variables
Add all required environment variables in Vercel dashboard:
- Go to Project Settings → Environment Variables
- Add each variable from your
.envfile - Select environments: Production, Preview, Development
- Click "Save"
Critical variables:
# Site
SITE_URL=https://yourdomain.com
NEXT_PUBLIC_SITE_URL=https://yourdomain.com
# Clerk (production keys)
CLERK_SECRET_KEY=sk_live_...
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_live_...
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
# Stripe (live keys)
STRIPE_SECRET_KEY=sk_live_...
STRIPE_PUBLISHABLE_KEY=pk_live_...
STRIPE_WEBHOOK_SECRET=whsec_...
# Database (Supabase production)
DATABASE_URL=postgresql://...
DIRECT_URL=postgresql://...
# AWS S3
AWS_ACCESS_KEY_ID=AKIA...
AWS_SECRET_ACCESS_KEY=...
AWS_S3_BUCKET=your-bucket
AWS_S3_REGION=us-east-1
AWS_S3_ENDPOINT=https://s3.amazonaws.com
# Email
RESEND_API_KEY=re_...
# Mailchimp
MAILCHIMP_API_KEY=...
MAILCHIMP_API_SERVER=us1
MAILCHIMP_AUDIENCE_ID=...
# Analytics
NEXT_PUBLIC_POSTHOG_KEY=phc_...
NEXT_PUBLIC_POSTHOG_HOST=https://eu.i.posthog.comDeploy
Click "Deploy" and wait for build to complete (2-3 minutes).
Deployment process:
- Clones repository
- Installs dependencies
- Runs
postinstallscript (Prisma generate + Fumadocs) - Builds application
- Runs
postbuildscript (sitemap generation) - Deploys to Vercel Edge Network
Verify Deployment
- Check deployment URL (e.g.,
your-project.vercel.app) - Test authentication (Clerk)
- Test payment flow (Stripe)
- Verify database connection
- Check email sending (Resend)
Custom Domain
Follow Vercel's domain setup guide to add a custom domain. After adding your domain, update these integration endpoints:
- Clerk: Add production domain in Clerk Dashboard → Domains
- Stripe: Update webhook endpoint to
https://yourdomain.com/api/stripe/webhook - Environment Variables: Update
SITE_URLandNEXT_PUBLIC_SITE_URLin Vercel
Database Migrations
Production Migration Strategy
Test Locally
# Create migration
npx prisma migrate dev --name add_new_feature
# Test migration
npm run build
npm run startPush to Repository
git add prisma/migrations
git commit -m "feat(db): add new feature migration"
git push origin mainDeploy Migration
Vercel automatically runs postinstall which includes prisma generate.
For applying migrations in production:
# Option 1: Run manually via Vercel CLI
vercel env pull .env.production
npx prisma migrate deploy
# Option 2: Add to build command (not recommended for large migrations)
# Modify package.json:
"build": "prisma migrate deploy && next build"Production migration best practices:
- Always test migrations locally first
- Backup database before major migrations
- Use
prisma migrate deploy(notmigrate dev) in production - Consider downtime for breaking schema changes
Monitoring & Logs
Vercel Dashboard
Deployment logs:
- Build output
- Runtime errors
- Function invocations
- Edge network metrics
Real-time logs:
- Go to Project → Deployments
- Click on deployment
- View "Functions" tab for runtime logs
Error Tracking
Built-in error reporting:
- Automatic error capture in production
- Stack traces in Vercel dashboard
- Function execution logs
PostHog integration:
// Automatic error tracking
posthog.capture('$exception', {
error: error.message,
stack: error.stack,
});Troubleshooting
Deployment Checklist
Before deploying to production:
- All environment variables configured in Vercel
- Database migrations tested locally
- Stripe webhooks configured with production endpoint
- Clerk production instance configured
- Custom domain DNS configured
- SSL certificate provisioned (automatic)
- S3 bucket CORS configured
- Email sending tested (Resend)
- Analytics tracking verified (PostHog)
- Error monitoring enabled
- Build succeeds locally:
npm run build - Production build tested:
npm run start - All integrations tested on staging/preview deployment
Preview Deployments
Vercel automatically creates preview deployments for:
- Pull requests
- Branch pushes
- Manual deployments
Preview features:
- Unique URL per deployment
- Same environment variables as production (or custom)
- Full functionality testing before merge
- Automatic comments on PRs with preview URL
Test on preview:
# Get preview URL from Vercel dashboard or PR comment
https://your-project-git-feature-branch.vercel.appNext Steps
- Environment Variables - Detailed variable configuration
- Troubleshooting - Common issues and solutions
- Git Workflow - Commit and push best practices
- Database Setup - Database configuration guide
How is this guide ?
Last updated on