GithubHelp home page GithubHelp logo

cheesehero112 / vite-to-gh-pages Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 319 KB

In this repo, we explain how to deploy a Vite React application created with a CICD pipeline. A Medium article is also available.

Home Page: https://chihiro-and-justin.medium.com/deploy-a-react-vite-app-using-github-actions-and-github-pages-a370df30da97

HTML 9.20% CSS 42.62% TypeScript 48.18%
cicd-pipeline github-actions github-pages react typescript vite

vite-to-gh-pages's Introduction

vite-to-gh-pages

vite-to-gh-pages-screenshot

Introduction

In this repo, we explain how to deploy a Vite React application created with a CICD pipeline. A Medium article is also available.

The website is deployed on GitHub pages.

All changes pushed to main branch will automatically be built and deployed using GitHub Actions.

Implementation Steps

1) Setup Web App Locally

  1. Navigate to the directory where you want the repo directory to be.
  2. Create ssd-app using npm create vite@latest
  3. Use name ssd-app, select React, and select Typescript.
  4. Move into folder cd ssd-app
  5. Install using npm i
  6. To test and see the application run npm run dev and view the app in your browser

2) Setup GitHub Pages Deployment

  1. Run npm install gh-pages --save-dev
  2. Install using npm i
  3. Create GitHub repo and link up with our local repo:
git init
git add .
git commit -m "first-commit"
git branch -M main
git remote add origin https://github.com/username/vite-to-gh-pages.git
git push -u origin main
  1. Update vite.config.js to include our repo name:
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

// https://vitejs.dev/config/
export default defineConfig({
  base: '/vite-to-gh-pages/',
  plugins: [react()],
});
  1. Run npm run build in your terminal.
  2. Add /dist folder into your repo by running git add dist -f
  3. Run git commit -m "Adding dist"
  4. Run git subtree push --prefix dist origin gh-pages
  5. Navigate to your GH Pages live page to verify your site is live.

3) Setup GitHub Actions to rebuild your site on commit to main

  1. To allow GitHub action to update our build go to your repo Settings > Actions > General > Workflow permisions to select Read and write permissions. Our change will allow the action to update the build in the gh-pages branch with each push.
  2. Add .github/workflows/node.js.yml the root project folder. Populate the file with the following text:
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node

# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        node-version: [18.x]
        # See supported Node.js release schedule at https://nodejs.org/en/about/releases/

    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: '18.x'
      - run: npm install
      - run: npm run build
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist
  1. Make a visible change to the web app you can use to verify the update.
  2. Run git add .
  3. Run git commit -m "add GH Action"
  4. Open your GH Pages web app to veriy your change has been made.

References

Contributers

GitHub LinkedIn
Justin Snider @sniderjustin @sniderj
Chihiro Snider @cheesehero112 @chihiro-snider

vite-to-gh-pages's People

Contributors

cheesehero112 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.