| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
* created using create-react-app
In this tutorial, I'll show you how I deployed a React app—which I created using create-react-app—to GitHub Pages.
You can visit the deployed app, at https://gitname.github.io/react-gh-pages/.
This repository contains the files related to the app. The master branch contains the app's source code (the code the app's developers edit), and the gh-pages branch contains a built version of the app (i.e. the code that GitHub Pages serves to the app's visitors).
The remainder of this document contains a tutorial on creating a React app (using create-react-app) and deploying that app to GitHub Pages.
An adequate version of Node.js is installed. Here's the adequate version I use:
$ node --version
v6.10.1An adequate version of npm is installed. Here's the adequate version I use:
$ npm --version
3.10.10An adequate version of create-react-app is installed. Here's the adequate version I use:
$ create-react-app --version
1.3.1In the case of create-react-app, you can either install it globally (i.e. $ npm install -g create-react-app) or install it locally (i.e. $ npm install create-react-app). If you choose the latter, you will have to specify its path whenever you invoke it (e.g. path/to/node_modules/.bin/create-react-app).
(Optional) An adequate version of sed is installed. Here's the adequate version I use:
$ sed --version
sed (GNU sed) 4.4A GitHub account. ![]()
A command-line Git client setup according to GitHub.
Create an empty repository on GitHub. (2 minutes)
Create a new React app on your computer. (5 minutes)
$ create-react-app react-gh-pagesInstall the gh-pages package as a "dev-dependency" of the app. (1 minute)
$ cd react-gh-pages $ npm install gh-pages --save-dev
Add some properties to the app's package.json file. (3 minutes)
//...
"homepage": "http://gitname.github.io/react-gh-pages""scripts": {
//...
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}$ sed -i '5i\ "homepage": "http://gitname.github.io/react-gh-pages",' ./package.json
$ sed -i '15i\ "predeploy": "npm run build",' ./package.json
$ sed -i '16i\ "deploy": "gh-pages -d build",' ./package.jsonCreate a git repository in the app's folder. (1 minute)
$ git init Initialized empty Git repository in C:/path/to/react-gh-pages/.git/
Add the GitHub repository as a "remote" in your local git repository. (1 minute)
$ git remote add origin https://github.com/gitname/react-gh-pages.git
Generate a production build of your app, and deploy it to GitHub Pages. (2 minutes)
$ npm run deploy
Optionally, commit your source code to the "master" branch and push your commit to GitHub. (1 minute)
$ git add . $ git commit -m "Create a React app and publish it to GitHub Pages" $ git push origin master
| Back | FazBrowse Home | New Git URL |