Vercel deployment configuration and optimization for Next.js applications including vercel.json setup, environment variables, build optimization, edge functions, and deployment troubleshooting. Use when deploying to Vercel, configuring deployment settings, optimizing build performance, setting up environment variables, configuring edge functions, or when user mentions Vercel deployment, production setup, build errors, or deployment optimization.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
README.mdexamples/deployment-patterns.mdscripts/optimize-build.shscripts/setup-env-vars.shscripts/test-edge-functions.shscripts/validate-deployment.shtemplates/basic.vercel.jsontemplates/edge-functions.vercel.jsontemplates/env-template.mdtemplates/monorepo.vercel.jsontemplates/optimized.vercel.jsonPurpose: Configure and optimize Next.js deployments on Vercel with automated validation and best practices.
Activation Triggers:
Key Resources:
scripts/validate-deployment.sh - Validate deployment configurationscripts/optimize-build.sh - Analyze and optimize build performancescripts/setup-env-vars.sh - Interactive environment variable setupscripts/test-edge-functions.sh - Test edge function configurationtemplates/vercel.json - Production-ready vercel.json templatestemplates/env-template.md - Environment variable documentationexamples/deployment-patterns.md - Common deployment scenariosValidate configuration before deploying:
# Full deployment validation
./scripts/validate-deployment.sh
# Checks performed:
# - vercel.json syntax and schema
# - Environment variables documented
# - Build command configuration
# - Output directory exists
# - Framework detection correct
# - No hardcoded secrets in code
Choose appropriate template based on needs:
# Generate vercel.json from template
cp templates/vercel.json vercel.json
# Templates available:
# - basic.vercel.json → Minimal configuration
# - optimized.vercel.json → Performance optimized
# - edge-functions.vercel.json → With edge/middleware
# - monorepo.vercel.json → Monorepo setup
Key Configuration Options:
Build Settings:
buildCommand - Override build command (default: next build)installCommand - Custom install command or skip with ""outputDirectory - Build output location (default: .next)framework - Force framework detection (usually auto-detected)Routing:
cleanUrls - Remove .html extensions (true/false)trailingSlash - Enforce trailing slash behaviorredirects - 301/302/307/308 redirect rulesrewrites - Internal URL rewritesheaders - Custom response headersFunctions:
functions - Configure memory, duration, runtime per functionregions - Deployment regions (default: iad1)# Interactive setup
./scripts/setup-env-vars.sh
# Guided process:
# 1. Identifies required variables from code
# 2. Categorizes by environment (dev/preview/prod)
# 3. Generates .env.local and .env.example
# 4. Provides Vercel CLI commands for upload
Best Practices:
.env.local or .env.production.env.example (no values)NEXT_PUBLIC_templates/env-template.mdUpload to Vercel:
# Production
vercel env add VARIABLE_NAME production
# Preview
vercel env add VARIABLE_NAME preview
# Development
vercel env add VARIABLE_NAME development
# Pull to local
vercel env pull .env.local
# Analyze build performance
./scripts/optimize-build.sh
# Provides:
# - Bundle size analysis
# - Build time breakdown
# - Optimization recommendations
# - Tree-shaking opportunities
# - Code-splitting suggestions
Common Optimizations:
Image Optimization:
{
"images": {
"domains": ["cdn.example.com"],
"formats": ["image/avif", "image/webp"],
"minimumCacheTTL": 60
}
}
Function Configuration:
{
"functions": {
"app/api/**/*.ts": {
"memory": 1024,
"maxDuration": 10
}
}
}
Build Cache:
node_modules/.cache is in .gitignore# Test edge function configuration
./scripts/test-edge-functions.sh
# Validates:
# - Edge runtime compatibility
# - No Node.js-specific APIs
# - Size limits (1MB compressed)
# - Cold start performance
Edge Configuration in next.config.js:
export const runtime = 'edge'
export const preferredRegion = 'iad1'
Common Edge Use Cases:
# Connect Git repository via Vercel Dashboard
# Automatic deployments on:
# - main/master → Production
# - other branches → Preview
# Manual trigger via commit
git push origin main
# Install CLI
npm i -g vercel
# Preview deployment
vercel
# Production deployment
vercel --prod
# With environment
vercel --prod --env NEXT_PUBLIC_API_URL=https://api.example.com
Custom deployment triggers without Git push:
# Create hook in Vercel Dashboard → Settings → Git → Deploy Hooks
# Then trigger via HTTP:
curl -X POST https://api.vercel.com/v1/integrations/deploy/[hook-id]
Module not found:
# Verify all dependencies in package.json
npm install --frozen-lockfile
# Check for case-sensitive import issues
# Vercel is case-sensitive, local dev may not be
Out of memory:
{
"builds": [{
"src": "package.json",
"use": "@vercel/next",
"config": {
"maxLambdaSize": "50mb"
}
}]
}
Build timeout:
# Verify variables are set
vercel env ls
# Check variable is available
vercel env pull .env.local
cat .env.local
# Common mistakes:
# - Forgot NEXT_PUBLIC_ prefix for client-side
# - Set in wrong environment (dev/preview/prod)
# - Contains quotes or spaces incorrectly
Function size exceeded:
vercel buildFunction timeout:
Custom domain not working:
# Verify DNS settings
dig yourdomain.com
# Should show:
# A record → 76.76.21.21
# or CNAME → cname.vercel-dns.com
Preview URLs:
project-git-branch-team.vercel.app{
"$schema": "https://openapi.vercel.sh/vercel.json",
"buildCommand": "next build",
"outputDirectory": ".next",
"framework": "nextjs",
"headers": [
{
"source": "/(.*)",
"headers": [
{
"key": "X-Content-Type-Options",
"value": "nosniff"
},
{
"key": "X-Frame-Options",
"value": "DENY"
}
]
}
]
}
{
"buildCommand": "cd ../.. && npm run build --filter=web",
"installCommand": "npm install --prefix=../.. --frozen-lockfile",
"outputDirectory": ".next"
}
{
"rewrites": [
{
"source": "/api/:path*",
"destination": "https://api.example.com/:path*"
},
{
"source": "/blog/:slug",
"destination": "/news/:slug"
}
]
}
Scripts: All scripts in scripts/ are executable and include:
validate-deployment.sh - Pre-deployment validationoptimize-build.sh - Build performance analysissetup-env-vars.sh - Environment variable configurationtest-edge-functions.sh - Edge function testingcheck-bundle-size.sh - Bundle analysisTemplates: templates/ contains:
Examples: examples/deployment-patterns.md includes:
Platform: Vercel Framework: Next.js 13+ (App Router and Pages Router) CLI Version: Latest Vercel CLI Version: 1.0.0