All Projects → gitname → React Gh Pages

gitname / React Gh Pages

Deploying a React App (created using create-react-app) to GitHub Pages

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to React Gh Pages

Youtube React
A Youtube clone built in React, Redux, Redux-saga
Stars: ✭ 421 (-84.97%)
Mutual labels:  create-react-app, tutorial
React Native Web Monorepo
Code sharing between iOS, Android & Web using monorepo
Stars: ✭ 697 (-75.12%)
Mutual labels:  create-react-app, tutorial
Phoenix Chat Example
💬 A Step-by-Step Beginners Tutorial for Building, Testing & Deploying a Chat app in Phoenix 1.5.5 🚀
Stars: ✭ 452 (-83.86%)
Mutual labels:  tutorial, deployment
react-production-deployment
Deploy your React app to production on Netlify, Vercel and Heroku
Stars: ✭ 51 (-98.18%)
Mutual labels:  deployment, create-react-app
Binari
Interactive code editor with a live binary tree visual designed to teach new developers the fundamentals of dynamic programming.
Stars: ✭ 82 (-97.07%)
Mutual labels:  tutorial, educational
Serverless Stack Com
An open source guide for building and deploying full-stack apps using Serverless and React on AWS.
Stars: ✭ 3,617 (+29.13%)
Mutual labels:  create-react-app, tutorial
React Tutorial
A walkthrough of basic React concepts.
Stars: ✭ 482 (-82.79%)
Mutual labels:  create-react-app, tutorial
jekyll-deploy-action
🪂 A Github Action to deploy the Jekyll site conveniently for GitHub Pages.
Stars: ✭ 162 (-94.22%)
Mutual labels:  deployment, gh-pages
Learning python
Source material for Python Like You Mean it
Stars: ✭ 78 (-97.22%)
Mutual labels:  tutorial, educational
Branchsite
CLI tool for publishing your static website to a separate branch
Stars: ✭ 65 (-97.68%)
Mutual labels:  gh-pages, deployment
Flingos
An educational operating system written in C#. A great stepping stone from high to low level development.
Stars: ✭ 451 (-83.9%)
Mutual labels:  tutorial, educational
Doctr
A tool for automatically deploying docs from Travis CI to GitHub pages.
Stars: ✭ 110 (-96.07%)
Mutual labels:  gh-pages, deployment
Bert In Production
A collection of resources on using BERT (https://arxiv.org/abs/1810.04805 ) and related Language Models in production environments.
Stars: ✭ 58 (-97.93%)
Mutual labels:  tutorial, deployment
Github Pages Deploy Action
Automatically deploy your project to GitHub Pages using GitHub Actions. This action can be configured to push your production-ready code into any branch you'd like.
Stars: ✭ 2,507 (-10.5%)
Mutual labels:  gh-pages, deployment
Cordova Create React App
A tutorial on how to set up a Cordova project using Create React App.
Stars: ✭ 167 (-94.04%)
Mutual labels:  create-react-app, tutorial
Judo Heroes 2
Universal Javascript sample application with React Router 4 and Express 5 (Enhanced version of https://github.com/lmammino/judo-heroes)
Stars: ✭ 182 (-93.5%)
Mutual labels:  tutorial
Docker For Java
Docker for Java Developers
Stars: ✭ 183 (-93.47%)
Mutual labels:  tutorial
Gooact
⚛️ React done in 160 lines of JavaScript.
Stars: ✭ 182 (-93.5%)
Mutual labels:  tutorial
Justchat
A chat application built with Django channels.
Stars: ✭ 183 (-93.47%)
Mutual labels:  tutorial
Zero To Preact
A Step-by-step Guide to Preact + Webpack 2, without boilerplate!
Stars: ✭ 185 (-93.4%)
Mutual labels:  tutorial

Deploying a React App* to GitHub Pages

* created using create-react-app

Introduction

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.

Tutorial

Prerequisites

  1. An adequate version of Node.js is installed. Here's the adequate version I use:

    $ node --version
    v6.10.1
  2. An adequate version of npm is installed. Here's the adequate version I use:

    $ npm --version
    3.10.10
  3. An adequate version of create-react-app is installed. Here's the adequate version I use:

    $ create-react-app --version
    1.3.1

    In 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).

  4. (Optional) An adequate version of sed is installed. Here's the adequate version I use:

    $ sed --version
    sed (GNU sed) 4.4
  5. A GitHub account. :octocat:

  6. A command-line Git client setup according to GitHub.

Procedure

  1. Create an empty repository on GitHub. (2 minutes)

    • For this tutorial, I'll create a repository named react-gh-pages.
    • By empty, I mean without a README.md file, a .gitignore file, a LICENSE file, or any other files.
  2. Create a new React app on your computer. (5 minutes)

    $ create-react-app react-gh-pages
    • This is the app you will deploy to GitHub Pages in step 7.
    • I opted to give the app the same name as my GitHub repository (i.e. react-gh-pages). However, you can name them differently from one another (e.g. you can name your app app-123 and your GitHub Repository repo-456).
    • This will create a new folder named react-gh-pages (or whatever you named your app) on your computer.
  3. Install the gh-pages package as a "dev-dependency" of the app. (1 minute)

    $ cd react-gh-pages
    $ npm install gh-pages --save-dev
    
    • The commands shown in the following steps can all be issued from within the app's folder.
  4. Add some properties to the app's package.json file. (3 minutes)

    • At the top level, add a homepage property. Define its value to be the string http://{username}.github.io/{repo-name}, where {username} is your GitHub username, and {repo-name} is the name of the GitHub repository you created in step 1. Since my GitHub username is gitname and the name of my GitHub repository is react-gh-pages, I added the following property:
    //...
    "homepage": "http://gitname.github.io/react-gh-pages"
    • In the existing scripts property, add a predeploy property and a deploy property, each having the values shown below:
    "scripts": {
      //...
      "predeploy": "npm run build",
      "deploy": "gh-pages -d build"
    }
    • Shortcut: Instead of adding those properties using a text editor; if I have sed installed on my system, I can add the properties by issuing the following shell commands:
    $ 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.json
  5. Create a git repository in the app's folder. (1 minute)

    $ git init
    Initialized empty Git repository in C:/path/to/react-gh-pages/.git/
    
  6. 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
    
    • This will make it so the gh-pages package knows where you want it to deploy your app in step 7.
    • It will also make it so git knows where you want it to push your source code (i.e. the commits on your master branch) in step 8.
  7. Generate a production build of your app, and deploy it to GitHub Pages. (2 minutes)

    $ npm run deploy
    
    • That's it! Your app is now accessible at the URL you specified in step 4.
    • In my case, my app is now accessible at: https://gitname.github.io/react-gh-pages/
    • I recommend exploring the GitHub repository at this point. When I explored it, I noticed that, although a master branch did not exist, a gh-pages branch did exist. I noticed the latter contained the built app code, as opposed to the app's source code.
  8. 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
    
    • I recommend exploring the GitHub repository once again at this point. When I did that, I noticed that a master branch now existed, and it contained the app's source code.
    • So, the master branch held the source code, and the gh-pages branch held the built app code.

References

  1. Facebook's tutorial on deploying a React app to GitHub Pages

Notes

  • I created this React app using create-react-app. By default, apps created using create-react-app have a README.md file that looks like this. Indeed, the README.md file you're now reading originally looked like that. I have since changed it to look the way it looks today.
  • Special thanks to GitHub, Inc., for providing us with the GitHub Pages hosting functionality at no extra charge.
  • And now, time to turn the default create-react-app app into something unique!
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].