AgentSkillsCN

github-vercel-deploy

部署至 GitHub 和 Vercel。在推送到 GitHub 时使用,包括配置“推送时部署”、设置 vercel.json、将仓库连接到 Vercel、为部署配置环境变量,或当用户询问如何部署至 GitHub 或 Vercel 时使用。

SKILL.md
--- frontmatter
name: github-vercel-deploy
description: Deploy to GitHub and Vercel. Use when pushing to GitHub, configuring deploy-on-push, setting up vercel.json, connecting a repo to Vercel, configuring environment variables for deployment, or when the user asks about deploying to GitHub or Vercel.

GitHub & Vercel Deployment

When to Use

  • User wants to deploy to Vercel, push to GitHub, or set up deploy-on-push
  • User mentions GitHub, Vercel, production, preview deployment, or vercel.json
  • Configuring repo connection, build settings, SPA routing, or env vars for deployment

Workflow: Push → Deploy

  1. Push to GitHub → Vercel detects push and builds automatically (when repo is connected)
  2. Production: Default branch (e.g. main) → Production URL
  3. Preview: Other branches and PRs → Preview URLs

GitHub Checklist

  • Repo exists on GitHub; local remotes point correctly (git remote -v)
  • Branch to deploy from (e.g. main) is pushed and up to date
  • No uncommitted changes blocking deploy (git status)
bash
git add .
git commit -m "chore: deploy"
git push origin main

Vercel Setup

Connect Repo

  1. Vercel Dashboard → Add New Project
  2. Import Git Repository → choose the GitHub repo
  3. Confirm root directory (usually project root)
  4. Vercel auto-detects Vite; verify build settings

vercel.json

Keep config minimal. For Vite + HashRouter (SPA):

json
{
  "framework": "vite",
  "buildCommand": "npm run build",
  "outputDirectory": "dist",
  "rewrites": [{ "source": "/(.*)", "destination": "/index.html" }]
}
  • rewrites: Required for client-side routing (HashRouter uses #; standard SPA rewrite still recommended for consistency)
  • outputDirectory: Must match Vite output (dist)

Environment Variables

Set in Vercel: Project → Settings → Environment Variables.

VariableEnvironmentPurpose
VITE_SUPABASE_URLProduction, PreviewSupabase project URL
VITE_SUPABASE_ANON_KEYProduction, PreviewSupabase anon key
VITE_GEMINI_API_KEYProduction, PreviewGemini AI (if used in build)
VITE_EBAY_*Production, PrevieweBay API (if used)
  • Never commit secrets; use Vercel env only
  • Choose Production, Preview, and/or Development per variable

Pre-Deploy Checklist

  • npm run build succeeds locally
  • vercel.json has correct outputDirectory and SPA rewrites
  • Env vars set in Vercel for the target environment
  • Production branch configured in Vercel (Settings → Git)

Common Issues

ProblemFix
404 on refresh or direct URLAdd SPA rewrite in vercel.json
Build failsCheck Node version; add engines.node in package.json if needed
Wrong branch deploysVercel → Settings → Git → Production Branch
Missing env in buildEnsure vars set for Production or Preview as needed
HashRouter URLs not workingRewrite /(.*)/index.html covers hash routes

Optional: Vercel CLI

bash
npx vercel          # Preview deploy
npx vercel --prod   # Production deploy (use with care)

Useful for testing config without pushing.


Reference