Given your repo where your working react app is on, let's say, working-react-app
branch, and all the following steps (except step 1) happen on this branch.
-
Create a new branch
gh-pages
on your repo page (from whichever branch you want because the wholegh-pages
branch content will be later replaced with you built app anyway) and then go to Settings | Options | GitHub Pages to make sure thegh-pages
branch is selected as the source: -
Install
gh-pages
:npm install --save-dev gh-pages
-
Add
homepage
field in yourpackage.json
indicating your GitHub Pages URL for your repo:{ // ... "homepage": "http://yourusername.github.io/your-react-repo-name/" // ... }
e.g. for this repo, it is
{ // ... "homepage": "http://augustusz.github.io/github-page-react-app/" // ... }
-
Then, add the following script in your
package.json
{ // ... "scripts": { // ... "predeploy": "npm run build", "deploy": "gh-pages -d build" } }
Now you should have all the confgiration your need for the deployment.
After configure for the first time, (or every time you update your app code and you want to depoly it) simply run
npm run deploy
Input your username and password.
When you see Published
logged, the depolyment is done. You should see your deployed app on the homepage
URL now.