How to deploy React app using GitHub Actions?
Make sure you have these things in your device: Check if they are installed by
Open your package.json file where you will need to add some deployment scripts.
"homepage": "https://(your_github_username).github.io/(repository_name)",
Next add these scripts
scripts:{ "predeploy": "npm run build", "deploy": "gh-pages -d build" }
Should look like this:
Now push the repo to your github account. Using simple flow of these commands respectively:
git add .
git commit -m "your_message"
git push
After you are done. Open your CLI (command line interface) and enter these commands:
$ npm run deploy
That will cause thepredeploy
anddeploy
scripts defined inpackage.json
to run .Under the hood, thepredeploy
script will build a distributable version of the React app and store it in a folder namedbuild
. Then, thedeploy
script will push the contents of that folder to a new commit on thegh-pages
branch of the GitHub repository, creating that branch if it doesn't already exist.$ npm run deploy
You can also specify a commit message by
$ npm run deploy -- -m "Deploy React app to GitHub Pages"
At this point, the react app has been successfully deployed on your site and is accessible at:
https://(your_username).github.io(repository_name)
Subscribe to my newsletter
Read articles from Gaurab Wagle directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Gaurab Wagle
Gaurab Wagle
CS - KU, Nepal. Exploring my ways as a developer. Available for collaboration on projects