
Apr 26, 2024
•
#react
#vite
#github
#git
•
2 mins read
Let’s start by scaffolding a new React project using Vite:
npm create vite@latestOnce the project is scaffolded, navigate to the project directory and install dependencies:
cd vite-react-deploy
npm installCreate a new repository on GitHub:

Initialize Git, commit all the files and push them to your new repo:
git init
git add -A
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/[username]/[repo_name].git # Replace with your username and repo URL
git push -u origin mainWe’ve just successfully pushed our project to GitHub:

base path in vite.config.tsIf you won’t do this, you get a 404 error for each asset in your project:
// vite.config.ts
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
base: "/vite-react-deploy/", // YOUR REPO NAME HERE
});
Create a deploy.yml file inside the .github/workflows directory.
Copy and paste this workflow:
name: Deploy
on:
push:
branches:
- main
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v3
- name: Setup Node
uses: actions/setup-node@v3
- name: Install dependencies
uses: bahmutov/npm-install@v1
- name: Build project
run: npm run build
- name: Upload production-ready build files
uses: actions/upload-artifact@v4
with:
name: production-files
path: ./dist
deploy:
name: Deploy
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: production-files
path: ./dist
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./distPush those changes:
git add -A
git commit -m "deploy config"
git push
Actions → choose a failed deployment → Re-run failed jobs. Wait until in finishes.


Once the workflow finishes successfully, you'll see a new deployment on your GitHub Pages. Click the link to access your deployed Vite React application!
