How to deploy React app using GitHub Actions?

Gaurab WagleGaurab Wagle
1 min read

Make sure you have these things in your device: Check if they are installed by

  1. Open your package.json file where you will need to add some deployment scripts.

  2.   "homepage": "https://(your_github_username).github.io/(repository_name)",
    

  1. Next add these scripts

  2.  scripts:{
     "predeploy": "npm run build",
     "deploy": "gh-pages -d build"
     }
    
  3. 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:

  1. $ npm run deploy
    That will cause the predeploy and deploy scripts defined in package.json to run .Under the hood, the predeploy script will build a distributable version of the React app and store it in a folder named build. Then, the deploy script will push the contents of that folder to a new commit on the gh-pages branch of the GitHub repository, creating that branch if it doesn't already exist.
     $ npm run deploy
    
  2. You can also specify a commit message by

  3.  $ 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)

0
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