DEV Community

Cover image for React to Vercel: Deployment Made Easy.
Harshal Ranjhani for CodeParrot

Posted on • Originally published at 10xdev.codeparrot.ai

React to Vercel: Deployment Made Easy.

Deploying React apps can seem difficult, but tools like Vercel make it surprisingly simple. Vercel offers smooth deployment procedures and is an expert in hosting frontend frameworks. The following guide is designed for front-end developers who want to quickly and easily launch their React apps.

What is Vercel?

Vercel is a cloud platform that allows users to build, scale, and secure web experiences. Vercel handles all the tricky bits, like making sure your site loads fast and stays up, so you can focus on creating more awesome stuff. It's like having a backstage crew for your one-person show, making sure everything runs smoothly while you soak up the applause.

Creating a React app for deployment

You can either use your React app or create one from scratch by using Vite:

npx create-vite-app vercel-deployment --template react
Enter fullscreen mode Exit fullscreen mode

Now enter into the app by running:

cd vercel-deployment
Enter fullscreen mode Exit fullscreen mode

Install all the dependencies using:

npm install
Enter fullscreen mode Exit fullscreen mode

or if you're using yarn run:

yarn
Enter fullscreen mode Exit fullscreen mode

Install the vercel CLI:

npm install --global vercel
Enter fullscreen mode Exit fullscreen mode

or:

yarn add vercel
Enter fullscreen mode Exit fullscreen mode

This command will install the vercel CLI globally in your system so you don't have to download it every time.

Once this is done you can check whether vercel was successfully installed or not by running:

vercel --version
Enter fullscreen mode Exit fullscreen mode

If you see a version, you're good to go!
Now let's login to the vercel CLI by running:

vercel login
Enter fullscreen mode Exit fullscreen mode

You'll be prompted with various ways to login to vercel, you can select any one of those and proceed further.

Once you've successfully authenticated, run:

vercel
Enter fullscreen mode Exit fullscreen mode

This is a command used to create a new deployment in vercel. After running this you'll be prompted with a few basic questions to finish setting up your deployment. I would recommend just going with the defaults if you're unsure about anything!

After all of this is done you'll be prompted with the Production url, copy and paste that url in your browser and there it is, your app is now accessible to the world! πŸŽ‰

If you've followed along with me, you should see something like this on the unique url generated for you:

Deployment Preview

Bonus - Setting up a CI/CD pipeline

The approach we followed previously was good, but it would not be very helpful in cases where your code changes regularly. In that case, following the previous approach would mean that you'll have to re deploy every changed version of your code with a new url and new project each time.

Instead, we can set up a CI/CD pipeline directly on version which looks out for changes in your code using your github connected github repository to the project.

To do this just head over to Vercel and log in if you're not already logged in. If this is your first project, you'll be seeing something like this.

Vercel Dashboard

Select "Import new Project" or "Add Project" from the options and connect your github when prompted.

After you're authenticated, you'll be seeing a list of all the git repositories connected to your account. Just select the one that you want to deploy.

Git Repositories List

You should be prompted with something like this:
Project Initiation

Project Name

This is the name of your vercel project.

Framework Preset

If you're using something other than React to deploy to vercel, you can select it here.

Root Directory

Specify the root directory of your project. In this tutorial it will remain default.

Build and Output Variables

You can override build and installation commands here.

Environment variables

If you're using any environment variables, you can specify those here.

If you're following along, I'd recommend you to keep everything as default and just click on Deploy! πŸš€

It will start building your app, and you can check the logs in the given UI. After everything is successful you should be redirected to a dashboard page for your project with the public link for your react app.

The important thing here to note is that now whenever a new commit is pushed to the repository, the app will get updated automatically and there won't be any manual changes required!

Here is the preview of the deployment if you're following along:

Deployment Preview

Congratulations on deploying your project to Vercel! πŸš€ Now, it's time to shine and share your innovation with the world. 🌍✨

Top comments (0)