Skip to content

Instantly share code, notes, and snippets.

@bgrins
Last active February 14, 2023 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bgrins/4596ff293e7728d6dbf7021c8d0bb7d8 to your computer and use it in GitHub Desktop.
Save bgrins/4596ff293e7728d6dbf7021c8d0bb7d8 to your computer and use it in GitHub Desktop.

Create the project

If you don't already have one npm create vite@latest, and cd into the directory. Then:

git init
git add .
git commit -m "first-commit"
git branch -M main
git remote add origin http://github.com/username/repo-name.git
git push -u origin main

Create gh-pages branch

If you don't already have a gh-pages branch you can create an empty one like so:

git switch --orphan gh-pages
git commit --allow-empty -m "gh-pages"
git push origin gh-pages

Add files to the repo

Create a vite.config.js with:

import { defineConfig } from "vite";
export default defineConfig({
  base: "./",
});

Create a .github/workflows/node.js.yml with:

name: Node.js CI

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

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Use Node.js 18.x
        uses: actions/setup-node@v3
        with:
          node-version: 18.x
          cache: "npm"
      - run: npm install
      - run: npm run build --if-present

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          github_token: ${{ secrets.GITHUB_TOKEN }}
          publish_dir: ./dist

Update GitHub settings

At this point you should have an action running (replace your username/repo in https://github.com/bgrins/editor-tests/actions) which builds the project from scratch and publishes to the root of the gh-pages branch, making it available at something like https://bgrins.github.io/editor-tests/.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment