Jigar's blog

How to Deploy a React.js Application on Vercel

Deploy react app vercel.webp
Published on
/
3 mins read
/
––– views

Deploying a React.js application on Vercel is a seamless and efficient process. Vercel is a modern hosting platform optimized for frontend applications, offering automatic CI/CD, preview deployments, and powerful analytics.

🌟 Why Choose Vercel for React.js Deployment?

  • Zero Configuration – Deploy instantly with minimal setup.
  • Automatic CI/CD – Every push to your GitHub, GitLab, or Bitbucket triggers a deployment.
  • Scalability – Handles traffic spikes with ease.
  • Optimized Performance – Edge network for lightning-fast content delivery.
  • Built-in Analytics – Monitor user engagement and performance.

📌 Steps to Deploy a React.js Application on Vercel

Step 1: Prepare Your React.js Project

Ensure your React.js project is set up correctly:

npx create-react-app my-app
cd my-app
npm start

Before deployment, commit your code to a Git repository:

git init
git add .
git commit -m "Initial commit - React.js setup"
git branch -M main
git remote add origin <YOUR_GITHUB_REPOSITORY_URL>
git push -u origin main

Step 2: Connect to Vercel

  1. Sign in to Vercel at vercel.com.
  2. Click on "New Project".
  3. Import your Git repository (GitHub, GitLab, or Bitbucket).
  4. Select your project and click "Import".

Step 3: Configure Deployment Settings

  1. Project Name: Choose a unique name for your project.

  2. Framework Preset: Select Create React App.

  3. Root Directory: Leave it as the default (/).

  4. Environment Variables: Add essential variables (e.g., API keys, backend URLs):

    REACT_APP_API_URL=https://api.example.com
    GENERATE_SOURCEMAP=false
    
  5. Click Deploy and wait for Vercel to build and deploy your React app.

Step 4: Verify Deployment

Once the deployment is complete, Vercel will provide a live URL for your app. Visit the URL to ensure everything is working correctly.

📊 Enable Vercel Analytics

Vercel provides powerful analytics tools to monitor user traffic and performance.

Step 1: Enable Audiences in Vercel Analytics

  1. Open the Vercel Dashboard.
  2. Select your Project and go to the Analytics tab.
  3. Click Enable Audiences.

Step 2: Install Vercel Analytics Package

Add the analytics package to your project:

npm i @vercel/analytics  # Using npm
yarn add @vercel/analytics  # Using yarn

Step 3: Integrate Analytics in Your App

Modify your src/index.js or src/App.js:

import { inject } from '@vercel/analytics'
inject()

Step 4: Deploy Changes

Commit and push the updates to your Git repository:

git add .
git commit -m "Added Vercel Analytics"
git push origin main

Vercel will automatically redeploy your application with analytics enabled.

🎯 Summary of Commands

# Create and set up React project
npx create-react-app my-app
cd my-app
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <YOUR_GITHUB_REPOSITORY_URL>
git push -u origin main

# Install and integrate Vercel Analytics
npm i @vercel/analytics

🎉 Conclusion

Congratulations! 🎉 You have successfully deployed your React.js application on Vercel and enabled Vercel Analytics for tracking performance. Your application is now live and ready to scale!

🔗 Useful Links:

💬 Got questions? Drop a comment below and let's discuss! 🚀

Discussion (0)

🚀 Join the conversation!
Log in with GitHub or Google to share your thoughts and connect with the community.