Deploy Your React App using Vercel

Deploy Your React App using Vercel

In the realm of React development, getting your app live quickly and efficiently is crucial. Vercel offers a fantastic platform for deploying React applications, and integrating it with your existing GitHub workflow makes the process seamless. This blog post will guide you through publishing your React app on Vercel using your GitHub repository.

Prerequisites

Before diving in, ensure you have the following:

  • A React application (ideally created with create-react-app)

  • A GitHub account with your React app pushed as a remote repository

Approach 1: Vercel for Git

Vercel offers a streamlined deployment process directly from Git repositories. Here's how it works:

  1. Navigate to Vercel and sign up or sign in using your preferred method (e.g., GitHub, Google).

  2. Authorize Vercel to Access your GitHub Account: Vercel will request access to your GitHub repositories. Grant the necessary permissions.

  3. Select your React App Repository: Once authorized, Vercel will display a list of your GitHub repositories. Choose the one containing your React app.

  4. Deployment Settings (Optional): Vercel automatically detects React projects and configures appropriate build settings. You can review and adjust these settings if needed.

  5. Deploy! Click the "Deploy" button. Vercel will initiate the deployment process, building your app and making it live on a Vercel subdomain (e.g., yourappname.vercel.app).

Code Snippet (vercel.json):

{
  "version": 2,
  "builds": [
    { "src": "public", "use": "@vercel/static" }
  ]
}

This configuration tells Vercel to serve the contents of your public directory during deployment. You can place your built React app files within this directory.

Approach 2: Vercel CLI

For a more command-line-oriented approach, you can leverage the Vercel CLI. Here's the process:

  1. Install Vercel CLI: Run npm install -g vercel in your terminal.

  2. Navigate to your React App Directory: Use cd to reach your project's root directory.

  3. Login to Vercel: Run vercel login and follow the on-screen instructions to authenticate with Vercel.

  4. Deploy: Execute vercel in your terminal. Vercel will analyze your project, detect it as React, and initiate deployment.

Note: Ensure your project has a package.json file with the necessary scripts defined for building your React app (e.g., "build": "react-scripts build").

Conclusion

By following these steps, you'll successfully publish your React app on Vercel using your GitHub repository. Vercel offers additional features like custom domains, environment variables, and serverless functions, allowing you to scale your deployment as your React app grows.

Did you find this article valuable?

Support Abhishek's Blog by becoming a sponsor. Any amount is appreciated!