Github Pages is a nice way to host your website, it's completely free and very easy to deploy, and you can use it with any framework not only React. I didn't know that when I was a beginner and I thought it would be nice to share it.
Before starting, make sure your app is hosted in a Github Repository.
1. Install gh-pages
In your terminal type, npm install gh-pages --save-dev
or if you're using yarn yarn add gh-pages --dev
. The gh-pages dependency is what you're going to be using to deploy your app.
2. Add the scripts and the homepage URL
In your package.json
file add:
"homepage": "https://[your github username].github.io/[your project name]"
Make sure that your project name is the same used in your GitHub repository.
Then add to scripts:
"predeploy": "npm build",
"deploy": "gh-pages -d build"
3. Time to deploy
Finally, on your terminal type, npm run deploy
and that's it, as I said, very simple. It may take a couple of minutes before your app gets hosted but if everything works fine you should be able to see your app with the URL that you used for the homepage.
Top comments (1)
Thanks for sharing :)