Hosting react application using Github Pages

Hosting a react application using GitHub pages is pretty much easier, It automatically updates the production site when a new commit has been pushed to the main branch.

Here is the 3 easy steps to deploy your react application using GitHub pages:
Step 1:
First you need to install the npm module for GitHub pages using the below command:
npm i gh-pages --save-dev

Step 2:
You need to add the below code in your package.json file.
"homepage": "https://{github_username}.github.io/{repo_name}"
"scripts": {
	"predeploy": "npm run build",
	"deploy": "gh-pages -d build"
}
Step 3:
Use the below command to deploy your build file to a new branch called gh-pages.
npm run deploy
A sample repository for the same can be found here - github.com/gitname/react-gh-pages

Comments