DEV Community

L1GEND
L1GEND

Posted on

publish react app to github pages

How to deploy a React app to GitHub pages ? , React pages is a free static website hosting by github

1- Create New Repo : Create new github repo , Choose a username & add .github.io

example : yourname.github.io

Image description

2 - Install github pages dependency : Install **gh-pages **using the following command

npm install gh-pages — save-dev
Enter fullscreen mode Exit fullscreen mode

3 - Add Deploy & Homepage scripts : Add these two lines of code in your package.json file

"predeploy": "npm run build",
"deploy": "gh-pages -d build"
Enter fullscreen mode Exit fullscreen mode

Image description

Add Home Page Prop To The Same File :

"homepage": "https://yourname.github.io",
Enter fullscreen mode Exit fullscreen mode

Note replace your name with your git repo name

Image description

4- Deploy Your Static Website : run npm deploy to deploy your website

npm run deploy
Enter fullscreen mode Exit fullscreen mode

Top comments (0)