Deploying to Vercel
In this page:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
Zero-Config Deployment
Vercel automatically detects common frameworks (including Vite, Create React App, and especially Next.js) and configures the correct build command and output directory without you needing to specify anything manually, in most standard project setups.
Example: Deploying to Vercel from the CLI
$ npm install -g vercel
$ vercel login
$ vercel
# Vercel detects the Vite/CRA config automatically and deploys a preview
$ vercel --prod
⚠️ Run this in your own terminal or Node.js environment.
Handling Client-Side Routing
Just like Netlify, a React Router single-page app needs Vercel configured to serve index.html for every route, letting React Router handle the actual routing client-side, rather than Vercel trying (and failing) to find a real file for each path.
Example: The vercel.json Rewrite
$ cat vercel.json
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
⚠️ Run this in your own terminal or Node.js environment.
Production vs. Preview Environment Variables
Vercel automatically deploys every pull request as its own Preview deployment, separate from the Production deployment tied to your main branch. Environment variables can be configured differently for each, letting preview deployments point at a staging API while production points at the real one.
Example: Setting Vercel Environment Variables per Environment
$ vercel env add VITE_API_URL production
$ vercel env add VITE_API_URL preview
⚠️ Run this in your own terminal or Node.js environment.
- Not realizing Vercel's zero-config detection usually handles a standard Vite/React app automatically, so manually overriding build settings can sometimes cause more problems than it solves.
- Forgetting Vercel also needs a rewrite rule for client-side routing, similar to Netlify's redirect.
- Confusing Preview deployments (per pull request) with Production deployments (the main branch) when checking which environment variables apply.
- Vercel is another popular hosting platform, with particularly strong support for Next.js (its own creator) as well as plain React apps.
- It often auto-detects build settings for common frameworks with zero manual configuration needed.
- Client-side routing on Vercel needs a rewrite rule (vercel.json), the equivalent of Netlify's redirect.
- Vercel distinguishes Production deployments (main branch) from Preview deployments (other branches/PRs), each with potentially different environment variables.
No React-version restriction — a hosting/deployment workflow, not a code feature.
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first:
- Why Performance Matters
- Optimizing with React.memo
- Avoiding Unnecessary Re-renders
- Using the React Profiler
- Analyzing Bundle Size
- Image Optimization Techniques
- React as a PWA
- Creating a Production Build
- Environment Variables in React
- Deploying to Netlify
- Deploying to Vercel
- Basic CI/CD for React Apps
- SEO Basics for React SPAs