Prerequisites
Git installed.
GitHub Account created.
Node and npm installed.
Steps
Create an empty GitHub repository with visibility as public.
Create a simple React app through npm.
npx create-react-app simple-react-app cd simple-react-app
Install GitHub pages.
npm install gh-pages --save-dev
Edit Package.json and add the homepage URL.
{ "name": "my-app", "version": "0.1.0", + "homepage": "https://gitname.github.io/simple-react-app", "private": true,
Add deployment scripts as well to package.json.
"scripts": { + "predeploy": "npm run build", + "deploy": "gh-pages -d build", "start": "react-scripts start", "build": "react-scripts build",
Set Github remote origin URL.
git remote add origin https://github.com/gitname/simple-react-app.git
Deploy or push the react app to GitHub Pages.
npm run deploy -- -m "Deploy the React app to GitHub Pages"
Save the source code of the react app in
master
branch and the react app code ingh-pages
.git add . git commit -m "Configure React app for deployment to GitHub Pages" git push origin master
Now you can test the app deployed by clicking on the below URL.
Page - https://reevchris100.github.io/simple-react-app/
Repository - https://github.com/reevchris100/simple-react-app/tree/master