How to Deploy React App

How to Deploy React App

In this article, We will learn to deploy React app for free using Github pages and Vercel. These are very good place to deploy our web project quickly.

Goal: My main goal to provide you crisp content so that you donot need to waste your lot of time in reading many articles.

Prerequisites -

  1. A Github Account

  2. Node.js and npm install

  3. Basic Knowledge of React and Git

Compulsory Step :- Push your code to your github Repository

  • Create a Github Repository

Create a new reposity of with your app name
  • Run these Commands on your vs-code terminal under your react-app folder

Explanation-

  1. git init - This line will initialize your git repository

  2. git add . - This line will add all your changed files to staging area , you can look the changed files using git status command

  3. git commit -m "any message" - This line will commit the changes

  4. git branch -M main - This command will change your branch name from "master" to "main". This is not compuslary but standarization(i.e. recommended)

This command add a remote which will be used to push code to github

This line will push your code to github. You can check it by refreshing your github repository page.

Upto here, you have learnt to push react code to github.

Eg.

Your repo will look like this

Step : Deploy your github Repo using github pages

Install github pages, run this command under your app folder.

Add these lines to package.json.

Note: Add homepage line to the start of package.json and predeploy and deploy under scripts.

Run these line to update the changes and to deploy.

Last Step - Go to the pages under settings of your app repository

Hurray! Your app is live now. You can share this link to anyone.

Step : Deploy your React App on vercel

Note: Make sure there is no line like that present in your package.json. This can be added if you deploy your project over github pages earlier --

"homepage": "https://<Username>.github.io/<Repository-name>"

Run these lines under your react app folder in your vs-code terminal. Follow the process and select the options (Yes/No) as per your need as shown during while running these lines.

Explanation--

npm install -g vercel - This line will install vercel in your app.

npm run build - This line will create the production build for deployment of your react app

vercel login - This line will connect your vercel account with CLI. Login using your github account ( i.e. Recommended by me )

vercel --prod - This line will deploy your app to vercel using their pre-setup pipeline.

deployed project layout

Hurray! You have learnt two methods of deployment for your React app.

STAY TUNED, FOR UPCOMING ARTICLES

HAPPY CODING!

HAPPY DEVELOPEMENT!

#FOLLOW ME FOR SUCH AMAZING CRISP CONTENT

Hasnain Abbas

CEO & Co-Founder at Sawaine | Top-rated Freelancer | Senior. Front-End Developer

1y

great

To view or add a comment, sign in

Others also viewed

Explore topics