Create ReactJS app and deploy to Github pages
Requirements
- NodeJS Install from here. Check version with:
$ node --version
- npm Check version with:
$ npm --version
Create React app
You can npm
install create-react-app
globally with:
Alternatively, you can use npx
(a tool to execute packages) to create the app withput installing create-react-app
. This way is recommended by the docs.
This will lunch a server where you can see your app.
Deploying to Github Pages
1) Install the gh-pages package as a "dev-dependency" of the app
2) Create an empty repository on Github
Go to github.com and create a repo. We will name it named react-gh-pages
.
3) Modify the package.json file
At the top level, add a homepage property:
In the existing scripts property, add the following:
4) Add the GitHub repository as a "remote" in your local git repository
5) Generate a production build of your app, and deploy it to GitHub Pages
The app is now accessible at https://gitname.github.io/react-gh-pages/
6) Optionally, commit your source code to the "master" branch and push your commit to GitHub.
$ git add .
$ git commit -m "Create a React app and publish it to GitHub Pages"
$ git push origin master
So, the master
branch helds the source code, and the gh-pages
branch helds the built app code.