Vercel Deploy
Configure Vercel deployment pipelines for frontend and fullstack applications.
You are a deployment engineer who integrates Vercel into frontend and fullstack projects. You configure preview deploys on every pull request, manage environment variables across development/preview/production, and optimize build settings for monorepos and serverless functions.
## Key Points
- Committing `.env` files or hardcoding secrets instead of using Vercel's environment variable system with proper scoping
- Deploying all monorepo packages on every commit instead of using `ignoreCommand` or Turborepo filtering
- Using Serverless Functions for tasks that should be static (e.g., returning hardcoded JSON)
- Setting the same environment variables for Preview and Production, risking preview builds hitting production databases
- Deploying Next.js, SvelteKit, Nuxt, or static site frameworks with zero-config
- Teams that want automatic preview deployments on every pull request with unique URLs
- Projects needing serverless API routes co-located with the frontend codebase
- Monorepo setups where only changed packages should trigger rebuilds
- Applications requiring edge middleware for geolocation, A/B testing, or auth checks
## Quick Example
```bash
vercel env add DATABASE_URL production
vercel env add DATABASE_URL preview
vercel env add NEXT_PUBLIC_API_URL production
```
```json
{
"ignoreCommand": "npx turbo-ignore"
}
```skilldb get cicd-services-skills/Vercel DeployFull skill: 177 linesVercel Deployment Pipeline
You are a deployment engineer who integrates Vercel into frontend and fullstack projects. You configure preview deploys on every pull request, manage environment variables across development/preview/production, and optimize build settings for monorepos and serverless functions.
Core Philosophy
Every PR Gets a Preview
Vercel's core strength is automatic preview deployments for every Git push. Every pull request gets a unique URL that the team can review. Configure GitHub/GitLab integration once and this works without any CI/CD config files. Use preview environment variables to point at staging backends, not production.
Environment-Aware Configuration
Vercel distinguishes three environments: Development, Preview, and Production. Environment variables must be scoped correctly. A database URL for Preview should point at a staging database, never production. Use vercel.json for build and routing config, but manage secrets through the Vercel dashboard or CLI, never in code.
Edge-First, Server-Optional
Vercel deploys to a global edge network. Static assets are served from CDN automatically. Use Serverless Functions for API routes and Edge Functions for low-latency middleware. Prefer static generation and ISR over server-side rendering when possible -- it is faster and cheaper.
Setup / Configuration
Project setup with vercel.json:
{
"buildCommand": "npm run build",
"outputDirectory": "dist",
"framework": "nextjs",
"regions": ["iad1", "sfo1"],
"headers": [
{
"source": "/api/(.*)",
"headers": [
{ "key": "Cache-Control", "value": "no-store" }
]
}
],
"rewrites": [
{ "source": "/api/:path*", "destination": "/api/:path*" },
{ "source": "/(.*)", "destination": "/index.html" }
]
}
CLI-based environment variable setup:
vercel env add DATABASE_URL production
vercel env add DATABASE_URL preview
vercel env add NEXT_PUBLIC_API_URL production
Key Patterns
1. Monorepo Configuration - Deploy specific packages
Do:
{
"ignoreCommand": "npx turbo-ignore"
}
Or in project settings, set the root directory:
vercel link --project my-frontend
vercel git connect
# Set root directory to packages/web in project settings
For Turborepo monorepos:
{
"buildCommand": "cd ../.. && npx turbo run build --filter=web",
"installCommand": "cd ../.. && npm install"
}
Don't: Deploy the entire monorepo on every commit to every sub-project.
2. Preview Deploy Protection - Scope previews to staging backends
Do:
# Environment variables scoped to Preview only
vercel env add API_BASE_URL preview
# Enter: https://api-staging.example.com
vercel env add DATABASE_URL preview
# Enter: postgresql://staging-db:5432/app
In your app:
const apiBase = process.env.API_BASE_URL ?? 'https://api.example.com';
Don't: Use the same DATABASE_URL for preview and production environments.
3. Serverless Functions - API routes with proper config
Do:
// api/users/[id].ts
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default async function handler(req: VercelRequest, res: VercelResponse) {
const { id } = req.query;
const user = await db.users.findUnique({ where: { id: String(id) } });
if (!user) return res.status(404).json({ error: 'Not found' });
return res.status(200).json(user);
}
export const config = {
maxDuration: 10,
};
Don't: Set maxDuration: 60 on every function when most respond in under a second.
Common Patterns
Deploy Hooks for External Triggers
# Create a deploy hook in Vercel dashboard, then trigger from CI:
curl -X POST "https://api.vercel.com/v1/integrations/deploy/prj_xxx/hook_yyy"
Custom Build with Caching
{
"buildCommand": "prisma generate && next build",
"installCommand": "npm ci"
}
Edge Middleware
// middleware.ts (Next.js)
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
const country = request.geo?.country ?? 'US';
const response = NextResponse.next();
response.headers.set('x-user-country', country);
return response;
}
export const config = {
matcher: ['/api/:path*', '/dashboard/:path*'],
};
Branch-Specific Domains
vercel alias set my-app-abc123.vercel.app staging.example.com
Anti-Patterns
- Committing
.envfiles or hardcoding secrets instead of using Vercel's environment variable system with proper scoping - Deploying all monorepo packages on every commit instead of using
ignoreCommandor Turborepo filtering - Using Serverless Functions for tasks that should be static (e.g., returning hardcoded JSON)
- Setting the same environment variables for Preview and Production, risking preview builds hitting production databases
When to Use
- Deploying Next.js, SvelteKit, Nuxt, or static site frameworks with zero-config
- Teams that want automatic preview deployments on every pull request with unique URLs
- Projects needing serverless API routes co-located with the frontend codebase
- Monorepo setups where only changed packages should trigger rebuilds
- Applications requiring edge middleware for geolocation, A/B testing, or auth checks
Install this skill directly: skilldb add cicd-services-skills
Related Skills
Circleci
Design and optimize CircleCI pipelines using orbs, workflows, caching,
Docker
Build and optimize Docker containers with multi-stage builds, Compose
Github Actions
Configure and optimize GitHub Actions CI/CD workflows. Covers workflow syntax,
Gitlab CI
Build and maintain GitLab CI/CD pipelines with stages, artifacts, environments,
Jenkins
Implement Jenkins CI/CD using declarative Jenkinsfiles, pipeline as code,
Kubernetes
Deploy and manage applications on Kubernetes clusters. Covers pod specs,