- NodeJS Install from here. Check version with:
$ node --version
- npm Check version with:
$ npm --version
You can npm
install create-react-app
globally with:
$ npm install -g create-react-app
$ create-react-app my-app
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.
$ npx create-react-app my-app
$ cd my-app
$ npm start
This will lunch a server where you can see your app.
$ npm install gh-pages --save-dev
Go to github.com and create a repo. We will name it named react-gh-pages
.
At the top level, add a homepage property:
"homepage": "https://gitname.github.io/react-gh-pages"
In the existing scripts property, add the following:
"scripts": {
//...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
$ git remote add origin https://github.com/gitname/react-gh-pages.git
$ npm run deploy
The app is now accessible at https://gitname.github.io/react-gh-pages/
$ 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.