git init git add -A
git commit -m 「第一次提交」
git 分支 -M main
git Remote add origin https://github.com/[username]/[repo_name].git # 替換為您的使用者名稱和倉庫 URL
git push -u origin main
在 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 });
新增 GitHub 工作流程
在.github/workflows目錄中建立一個deploy.yml檔。複製並貼上此工作流程:
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
操作 → 選擇失敗的部署 → 重新執行失敗的作業。等待完成。
專案名稱、連結名稱(基底值)或 Repo 名稱大多數同名建立。
以上是將 Vite React App 部署到 GitHub Pages 步驟:的詳細內容。更多資訊請關注PHP中文網其他相關文章!