Home >Web Front-end >JS Tutorial >Deploy Vite React App to GitHub Pages tep:
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 main
Set base path in vite.config.ts
/ 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 });
Add a GitHub workflow
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@v3 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@v3 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: ./dist
Actions → choose a failed deployment → Re-run failed jobs. Wait until in finishes.
Project name, Link name(base value) or Repo name most be same name create.
The above is the detailed content of Deploy Vite React App to GitHub Pages tep:. For more information, please follow other related articles on the PHP Chinese website!