How to Deploy a React App to Vercel in 5 Minutes (Step-by-Step Guide)
Deploying a modern web application used to require configuring web servers, setting up SSL certificates, and writing complex build scripts. Today, platforms like Vercel have transformed deployment into a seamless, automated process that takes only a few clicks.
Vercel—created by the team behind Next.js—is built specifically for frontend developers and static site generators. It offers automatic HTTPS, instant global CDN delivery, and automatic continuous integration every time you push code to your repository.
In this tutorial, you will learn how to deploy a React application (created with Vite or Create React App) to Vercel in under 5 minutes using two easy methods: Git integration and the Vercel CLI.
Prerequisites
Before starting, make sure you have the following ready:
A React application running locally on your computer.
Node.js and npm/yarn installed.
A free Vercel account (you can sign up using your GitHub, GitLab, or Bitbucket account at
).vercel.com A GitHub repository containing your React project code.
Method 1: Deploying via GitHub (Recommended)
Connecting Vercel to your GitHub repository is the best long-term method because it enables Continuous Deployment (CI/CD). Every time you push new code to your main branch, Vercel will automatically rebuild and update your live site.
Step 1: Push Your Code to GitHub
If your project is not yet on GitHub, run the following commands in your terminal:
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/your-username/your-repo-name.git
git push -u origin main
Step 2: Import Your Project into Vercel
Log in to your Vercel Dashboard.
Click the "Add New..." button in the top-right corner and select "Project".
Under "Import Git Repository", choose GitHub.
Search for your React repository and click "Import".
Step 3: Configure Project Settings
Vercel automatically detects most modern React frameworks (such as Vite or Create React App) and configures the build settings for you:
Framework Preset: React or Vite
Build Command:
npm run buildorvite buildOutput Directory:
buildordist
If your app uses environment variables, expand the Environment Variables section and add your key-value pairs here.
Step 4: Deploy!
Click the "Deploy" button. Vercel will clone your repository, run your build script, and publish your site to a global CDN. Within 30 to 60 seconds, you will receive a live URL ([https://your-project.vercel.app](https://your-project.vercel.app)).
Method 2: Deploying via Vercel CLI
If you prefer using the command line or don't want to use Git, you can deploy directly from your local terminal using the Vercel CLI.
Step 1: Install Vercel CLI
Run the following command in your terminal to install the CLI globally:
npm install -g vercel
Step 2: Log In to Vercel
Authenticate the CLI with your Vercel account:
vercel login
Follow the on-screen instructions to verify your email address or log in via your browser.
Step 3: Run the Deploy Command
Navigate to your React project directory and run:
vercel
The CLI will prompt you with a few quick setup questions:
Set up and deploy? Press
Y.Which scope? Select your account.
Link to existing project? Press
N.What's your project's name? Enter your project name or press Enter for the default.
In which directory is your code located? Press Enter (
./).
Vercel will build your project and give you a preview URL. Once you are satisfied and ready for production, run:
vercel --prod
Post-Deployment: Essential Next Steps
1. Fixing Single Page Application (SPA) 404 Routing Errors
If your React app uses React Router, you might notice that refreshing the page on a sub-route (like /dashboard or /about) results in a 404: NOT_FOUND error.
This happens because Vercel looks for a physical file named dashboard.html instead of serving index.html. To fix this, create a file named vercel.json in the root directory of your project with the following configuration:
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
Commit and push this file to GitHub, and Vercel will handle client-side routing smoothly.
2. Adding a Custom Domain
While Vercel gives you a free .vercel.app subdomain, connecting a custom top-level domain (yourdomain.com) improves brand trust and SEO performance:
Go to Project Settings > Domains in your Vercel Dashboard.
Enter your custom domain and click Add.
Update your domain registrar's DNS settings with the
Arecord orCNAMErecord provided by Vercel.
Summary
Deploying React applications no longer requires managing server hardware or complex pipelines. With Vercel, you get:
Instant production deployments in under 5 minutes.
Free SSL certificates out of the box.
Automated build previews for every pull request.
Whether you choose the GitHub integration for automated builds or the Vercel CLI for fast terminal deployments, Vercel provides one of the smoothest developer experiences available today.
Comments
Post a Comment