A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Monday, June 19, 2017

Deploy React Application as Github Pages

9:50:00 PM Posted by Satish , No comments
Note:
This feature is available with react-scripts@0.2.0 and higher.

Prerequisites:
  1. The project should be checked in to github.
  2. In project setting enable gh-pages

Step 1: Add homepage to package.json.

//...
"homepage": "https://myusername.github.io/my-app",
view raw json hosted with ❤ by GitHub

Step 2: Install gh-pages. 

npm install --save-dev gh-pages
view raw sh hosted with ❤ by GitHub

Step 3: Add the following scripts in your package.json.

// ...
"scripts": {
// ...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
view raw json hosted with ❤ by GitHub

The pre-deploy script will run automatically before deploy is run.

Step 3: Now deploy the application by running the below command

I have deployed a sample app.

bulletin-board

Code in Github.com

npm run deploy
view raw sh hosted with ❤ by GitHub

0 comments:

Post a Comment