../ Software Development
-rw-r--r--aguang1.8 KiB2 min read

Deploy Your React App as Github Pages.

Github Pages is a convenient way to publish a website for your project hosted on Github. In this article I'll introduce how to set up the Continuous Deployment Workflow based on Github Actions to build and deploy your React App to Github Pages.

Develop Your React App.

First, we use create-react-app tool to initialize a new project.

bash
npx create-react-app example-app

Setup Github Workflow.

Then we create a Github Workflow File .github/workflows/deploy-pages.yml. Every time we merge a pull request into master or push commits into master, it will trigger a Github Action to build and publish the build folder into branch gh-pages.

yml
name: Github Pages
on:
  push:
    branches:
      - master
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout 🛎️
        uses: actions/[email protected]

      - name: Install and Build 🔧
        run: |
          yarn 
          yarn build

      - name: Deploy 🚀
        uses: JamesIves/[email protected]
        with:
          branch: gh-pages
          folder: build

Config Github Pages Source.

Now, we need to go project settings page and change the Github Pages Source from the branch gh-pages.

After that, we can visit the Github Pages of this project.

References.

COMMAND INTERFACE

↑ ↓ navigate · Enter execute · Esc exit · try “whoami”

Loading filesystem…

:help aguang.xyz

A personal website disguised as an operating system.

Ctrl / Cmd + K
Command palette + full-text search
Tab / Shift + Tab
Move between links and controls
Enter
Open a focused link or search result
↑ / ↓ in search
Navigate search results
In a directory filter
Enter/Done or ↓ focuses a result; Esc clears the filter
Esc
Clear a search or close a window