Deploy Your React App To GitHub Pages



GitHub is not only popular for hosting repositories but also you can host your websites. And it absolutely free. Following are the steps to host your React js App to GitHub.

Steps:

  1. Create a GitHub repository.
  2. Open Terminal (or CMD) on your project folder.
  3. Run these commands: npm run build . A build folder will be created inside your project.
  4. Open package.json using any editor of your choice.
  5. Paste this line of code:
  6. "homepage": "http://<username>.github.io/<myapp>"
  7. Change "username" with your GitHub username and "myapp" with your repository name.
  8. Now the file will look something like this:
  9. Add these lines of code to package.json 
  10. "predeploy": "npm run build",
  11. "deploy": "gh-pages -d build"
  12. Now the file will look something like this: 
  13. Save the file after editing.
  14. Run this command on the terminal (or CMD) npm install --save-dev gh-pages .
  15. Now you should see these lines added to your package.json 

Lastly, run this command: npm run deploy .
That's it! Go to the URL that you have provided on the homepage in package.json file. (http://<username>.github.io/<myapp>).

Now you should see your website - up and running!










Popular Posts