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:

  1. A React application running locally on your computer.

  2. Node.js and npm/yarn installed.

  3. A free Vercel account (you can sign up using your GitHub, GitLab, or Bitbucket account at vercel.com).

  4. 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:

Bash
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

  1. Log in to your Vercel Dashboard.

  2. Click the "Add New..." button in the top-right corner and select "Project".

  3. Under "Import Git Repository", choose GitHub.

  4. 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 build or vite build

  • Output Directory: build or dist

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:

Bash
npm install -g vercel

Step 2: Log In to Vercel

Authenticate the CLI with your Vercel account:

Bash
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:

Bash
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:

Bash
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:

JSON
{
  "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:

  1. Go to Project Settings > Domains in your Vercel Dashboard.

  2. Enter your custom domain and click Add.

  3. Update your domain registrar's DNS settings with the A record or CNAME record 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

Popular posts from this blog

Bootstrap 6: New Features, Major Changes, and What Developers Need to Know

Why Reflections Disappear in Games When You Tilt the Camera

How Games Fake Underwater Worlds: Fog, Color Absorption and Caustics