Community编程与开发github.com

部署到 Vercel

将应用和网站部署到 Vercel。当用户请求执行部署操作(如“部署我的应用”、“部署并给我链接”、“推送上线”或“创建预览部署”)时使用。

部署到 Vercel 是什么?

该技能用于将项目部署到 Vercel,提供完整的工作流程:从检查项目状态(Git 远程仓库、Vercel 本地链接、CLI 认证状态、可用团队),到选择最佳部署方法(Git 推送、vercel deploy、或免认证回退脚本),再到输出部署 URL。它支持 Claude Code、claude.ai 和 Codex 等环境,并针对不同沙盒环境提供专门的回退方案。对于已通过 Git 关联的项目,它会先提交并推送代码,然后通过 vercel ls 获取预览 URL;对于未关联但有 CLI 认证的环境,它会先执行 vercel link 建立关联再部署;在无法安装或认证 CLI 的沙盒中,则使用本地 shell 脚本完成免认证部署并返回预览 URL 和认领 URL。该技能始终优先使用预览部署(除非用户明确要求生产部署),并确保在推送代码前获得用户明确许可。

兼容平台✓Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/alfathafp/portofolio-web-design/tree/HEAD/.agents/skills/deploy-to-vercel

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

部署到 Vercel 是做什么的?

将任何项目部署到 Vercel。始终部署为预览(非生产环境),除非用户明确要求生产部署。

目标是让用户进入最佳长期设置:项目通过 Git 推送部署与 Vercel 关联。下面的每种方法都试图让用户更接近这一状态。

第 1 步:收集项目状态

在执行以下四种检查后,再决定使用哪种方法:

# 1. 检查 Git 远程仓库
git remote get-url origin 2>/dev/null

# 2. 检查是否本地链接到 Vercel 项目(任一文件存在即表示已链接)
cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null

# 3. 检查 Vercel CLI 是否已安装并认证
vercel whoami 2>/dev/null

# 4. 列出可用团队(如果已认证)
vercel teams list --format json 2>/dev/null

团队选择

如果用户属于多个团队,则以项目符号列表形式展示所有可用的团队 slug,并询问要部署到哪个团队。用户选择团队后,立即进入下一步——不要询问额外的确认。

在所有后续 CLI 命令(vercel deploy、vercel link、vercel inspect 等)中通过 --scope 传递团队 slug:

vercel deploy [path] -y --no-wait --scope <team-slug>

如果项目已链接(.vercel/project.json 或 .vercel/repo.json 存在),则这些文件中的 orgId 决定了所属团队——无需再次询问。如果只有一个团队(或只有个人账户),则跳过提示直接使用。

关于 .vercel/ 目录: 已链接的项目具有以下任一文件:

  • .vercel/project.json — 由 vercel link 创建(单个项目链接)。包含 projectId 和 orgId。
  • .vercel/repo.json — 由 vercel link --repo 创建(基于仓库的链接)。包含 orgId、remoteName 以及将目录映射到 Vercel 项目 ID 的 projects 数组。

任一文件存在即表示项目已链接。检查两者。

不要在未链接的目录中使用 vercel project inspect、vercel ls 或 vercel link 检测状态——没有 .vercel/ 配置时,它们会交互式提示(或使用 --yes 时静默链接,产生副作用)。只有 vercel whoami 在任何地方运行都是安全的。

第 2 步:选择部署方法

已链接(.vercel/ 存在) + 有 Git 远程仓库 → Git 推送

这是理想状态。项目已链接并具有 Git 集成。

  1. 推送前询问用户。 未经明确批准绝不推送:

    此项目已通过 Git 连接到 Vercel。我可以提交并推送以触发部署。
    是否继续?
    
  2. 提交并推送:

    git add .
    git commit -m "deploy: <更改描述>"
    git push
    

    Vercel 会自动从推送触发构建。非生产分支获得预览部署;生产分支(通常是 main)获得生产部署。

  3. 获取预览 URL。 如果 CLI 已认证:

    sleep 5
    vercel ls --format json
    

    JSON 输出包含一个 deployments 数组。找到最新的条目——其 url 字段即为预览 URL。

    如果 CLI 未认证,则告知用户在 Vercel 仪表板或 Git 提供商的提交状态检查中查看预览 URL。


已链接(.vercel/ 存在) + 无 Git 远程仓库 → vercel deploy

项目已链接但没有 Git 仓库。直接使用 CLI 部署。

vercel deploy [path] -y --no-wait

使用 --no-wait 以便 CLI 立即返回部署 URL,而不是阻塞直到构建完成(构建可能需要一些时间)。然后通过以下命令检查部署状态:

vercel inspect <deployment-url>

对于生产部署(仅当用户明确要求时):

vercel deploy [path] --prod -y --no-wait

未链接 + CLI 已认证 → 先链接,再部署

CLI 可用但项目尚未链接。这是将用户带入最佳状态的时机。

  1. 询问用户要部署到哪个团队。 以项目符号列表形式展示第 1 步中的团队 slug。如果只有一个团队(或只有个人账户),则跳过此步骤。

  2. 选择团队后,直接进入链接。 告知用户将要执行的操作,但不要要求单独确认:

    正在将此项目链接到 <团队名称> 的 Vercel。这将创建一个用于部署的 Vercel 项目,
    并启用未来 Git 推送的自动部署。
    
  3. 如果存在 Git 远程仓库,则使用基于仓库的链接并指定所选团队 scope:

    vercel link --repo --scope <team-slug>
    

    这会读取 Git 远程 URL 并将其与从该仓库部署的现有 Vercel 项目匹配。它会创建 .vercel/repo.json。这比 vercel link(不带 --repo)可靠得多,后者尝试按目录名称匹配,当本地文件夹和 Vercel 项目名称不同时经常失败。

    如果没有 Git 远程仓库,则回退到标准链接:

    vercel link --scope <team-slug>
    

    这将提示用户选择或创建项目。它会创建 .vercel/project.json。

  4. 然后使用最佳可用方法部署:

    • 如果存在 Git 远程仓库 → 提交并推送(参见上面的 Git 推送方法)
    • 如果没有 Git 远程仓库 → vercel deploy [path] -y --no-wait --scope <team-slug>,然后 vercel inspect <url> 检查状态

未链接 + CLI 未认证 → 安装、认证、链接、部署

Vercel CLI 完全未设置。

  1. 安装 CLI(如果尚未安装):

    npm install -g vercel
    
  2. 认证:

    vercel login
    

    用户在浏览器中完成认证。如果在无法登录的非交互环境中运行,则跳到下面的免认证回退。

  3. 询问要部署到哪个团队 — 以项目符号列表形式展示 vercel teams list --format json 中的团队 slug。如果只有一个团队/个人账户,则跳过。选择后立即继续。

  4. 使用所选团队 scope 链接项目(如果存在 Git 远程仓库则使用 --repo,否则使用普通 vercel link):

    vercel link --repo --scope <team-slug>   # 如果存在 Git 远程仓库
    vercel link --scope <team-slug>          # 如果没有 Git 远程仓库
    
  5. 使用最佳可用方法部署(如果存在远程仓库则使用 Git 推送,否则使用 vercel deploy -y --no-wait --scope <team-slug>,然后 vercel inspect <url> 检查状态)。


免认证回退 — claude.ai 沙盒

何时使用: 当 CLI 无法在 claude.ai 沙盒中安装或认证时的最后手段。这不需要认证——它返回一个预览 URL(在线站点)和一个认领 URL(转移到你的 Vercel 账户)。

bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh [path]

参数:

  • path - 要部署的目录,或 .tgz 文件(默认为当前目录)

示例:

# 部署当前目录
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh

# 部署特定项目
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh /path/to/project

# 部署现有的 tar 包
bash /mnt/skills/user/deploy-to-vercel/resources/deploy.sh /path/to/project.tgz

脚本会自动从 package.json 检测框架,打包项目(排除 node_modules、.git、.env),上传并等待构建完成。

告知用户: "您的部署已就绪,地址为 [previewUrl]。请访问 [claimUrl] 认领并进行管理。"


免认证回退 — Codex 沙盒

何时使用: 在 Codex 沙盒中 CLI 可能未认证。Codex 默认在沙盒环境中运行——先尝试 CLI,如果认证失败则回退到部署脚本。

  1. 检查 Vercel CLI 是否已安装(此检查无需提权):

    command -v vercel
    
  2. 如果已安装 vercel,尝试使用 CLI 部署:

    vercel deploy [path] -y --no-wait
    
  3. 如果未安装 vercel,或 CLI 失败并显示 "No existing credentials found",则使用回退脚本:

    skill_dir="<skill-路径>"
    
    # 部署当前目录
    bash "$skill_dir/resources/deploy-codex.sh"
    
    # 部署特定项目
    bash "$skill_dir/resources/deploy-codex.sh" /path/to/project
    
    # 部署现有的 tar 包
    bash "$skill_dir/resources/deploy-codex.sh" /path/to/project.tgz
    

脚本处理框架检测、打包和部署。它会等待构建完成并返回包含 previewUrl 和 claimUrl 的 JSON。

告知用户: "您的部署已就绪,地址为 [previewUrl]。请访问 [claimUrl] 认领并进行管理。"

提权网络访问: 仅在沙盒阻止网络调用时对实际部署命令进行提权(sandbox_permissions=require_escalated)。不要对 command -v vercel 检查进行提权。


特定 Agent 说明

Claude Code / 基于终端的 agent

您拥有完全的 Shell 访问权限。不要使用 /mnt/skills/ 路径。直接使用 CLI 遵循上述决策流程。

对于免认证回退,从技能的安装位置运行部署脚本:

bash ~/.claude/skills/deploy-to-vercel/resources/deploy.sh [path]

路径可能因用户安装技能的位置而异。

沙盒环境(claude.ai)

您可能无法运行 vercel login 或 git push。直接转到免认证回退 — claude.ai 沙盒。

Codex

Codex 在沙盒中运行。首先检查 CLI 是否可用,然后回退到部署脚本。转到免认证回退 — Codex 沙盒。


输出

始终向用户显示部署 URL。

  • Git 推送: 使用 vercel ls --format json 查找预览 URL。如果 CLI 未认证,则告知用户查看 Vercel 仪表板或提交状态检查。
  • CLI 部署: 显示 vercel deploy --no-wait 返回的 URL。使用 vercel inspect <url> 检查构建状态并向用户报告。
  • 免认证回退: 同时显示预览 URL 和认领 URL:
    部署成功!
    
    预览 URL:https://my-app-abc123.vercel.app
    认领 URL:https://vercel.com/claim-deployment?code=...
    
    您可以通过预览 URL 查看站点。
    要将此部署转移到您的 Vercel 账户,请访问认领 URL。
    

不要通过 curl 或 fetch 验证已部署的 URL 是否可工作。只需返回链接。


故障排除

网络出口错误(claude.ai)

如果因 claude.ai 的网络限制导致部署失败,请告知用户:

由于网络限制,部署失败。要解决此问题:

1. 前往 https://claude.ai/settings/capabilities
2. 将 *.vercel.com 添加到允许的域名
3. 重新尝试部署

提权网络访问(Codex / 沙盒环境)

如果在沙盒环境中因网络问题(超时、DNS 错误、连接重置)导致部署失败,请使用提权权限重新运行(sandbox_permissions=require_escalated)。不要对初始 CLI 可用性检查进行提权——仅对实际部署命令进行提权。

向用户提供的示例指导:

部署需要提权网络访问才能部署到 Vercel。我可以使用提权权限重新运行
命令——是否继续?

CLI 认证失败

如果 vercel login 或 vercel deploy 因认证错误失败,则回退到免认证部署脚本(根据环境使用 claude.ai 或 Codex 变体)。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

alfathafp/portofolio-web-design

You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).

alfathafp/portofolio-web-design

Tests in real browsers via Chrome DevTools MCP. Use when building or debugging anything that runs in a browser. Use when you need to inspect the DOM, capture console errors, analyze network requests, profile performance, or verify visual output with real runtime data. Requires the chrome-devtools MCP server to be configured.

alfathafp/portofolio-web-design

Automates CI/CD pipeline setup. Use when setting up or modifying build and deployment pipelines. Use when you need to automate quality gates, configure test runners in CI, or establish deployment strategies.

alfathafp/portofolio-web-design

Conducts multi-axis code review. Use before merging any change. Use when reviewing code written by yourself, another agent, or a human. Use when you need to assess code quality across multiple dimensions before it enters the main branch. Use when asked to review a diff or a pull request, even when the diff is pasted inline.

alfathafp/portofolio-web-design

Simplifies code for clarity. Use when refactoring code for clarity without changing behavior. Use when code works but is harder to read, maintain, or extend than it should be. Use when reviewing code that has accumulated unnecessary complexity.

alfathafp/portofolio-web-design

Establishes a project's quality bar as a written contract and stops agents quietly lowering it. Interviews the user on which dimensions matter, supplies sane default thresholds when they have no number in mind, records everything in CONSTRAINTS.md, and watches the diff for a weakened bar — new @ts-ignore or eslint-disable suppressions, skipped or deleted tests, assertions stripped out, unimplemented stubs, thresholds edited down. Use when no quality bar is written down, when the user says "set up constraints" or "define our standards", when the user wants dimensions they care about — accessibility, web performance, coverage — set up as enforced constraints, when an agent keeps silencing checks or skipping tests to get to green, when you need a coverage or performance threshold and don't know what number to pick, or when an agent writes more code than anyone will read.

alfathafp/portofolio-web-design

Optimizes agent context setup. Use when starting a new session, when agent output quality degrades, when switching between tasks, or when you need to configure rules files and context for a project.

alfathafp/portofolio-web-design

Guides systematic root-cause debugging. Use when tests fail, builds break, something that worked yesterday broke, behavior doesn't match expectations, or you encounter any unexpected error. Use when you need to figure out what broke and why — a systematic approach to finding and fixing the root cause rather than guessing.

alfathafp/portofolio-web-design

Manages deprecation and migration. Use when removing old systems, APIs, or features. Use when migrating users from one implementation to another. Use when migrating a database schema in production, such as renaming or dropping a column without downtime (expand/contract). Use when deciding whether to maintain or sunset existing code.

alfathafp/portofolio-web-design

Use when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness.

alfathafp/portofolio-web-design

Use when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies

alfathafp/portofolio-web-design

Records decisions and documentation. Use when you need to document an architecture decision (ADR) or the reasoning behind a design choice, when changing public APIs, shipping features, or when you need to record context that future engineers and agents will need to understand the codebase.

alfathafp/portofolio-web-design

Subjects every non-trivial decision to a fresh-context adversarial review before it stands. Use when you want every assumption cross-examined before proceeding, when stress-testing a plan for hidden failure modes, when correctness matters more than speed, when working in unfamiliar code, when stakes are high (production auth, security-sensitive logic, a high-stakes migration, irreversible operations), or any time a confident output would be cheaper to verify now than to debug later.

alfathafp/portofolio-web-design

Use when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available

alfathafp/portofolio-web-design

Use when implementation is complete, all tests pass, and you need to decide how to integrate the work

alfathafp/portofolio-web-design

Builds production-quality, accessible, responsive user-facing UIs. Use when building or modifying interfaces and pages, creating components, implementing layouts, meeting WCAG accessibility requirements, managing state, or when the output needs to look and feel production-quality rather than AI-generated.

alfathafp/portofolio-web-design

Structures git workflow practices. Use when making any code change. Use when committing, branching, resolving conflicts, splitting uncommitted work in a messy working tree into clean atomic commits, opening or reviewing a pull request (PR), pushing to a remote, or when you need to organize work across multiple parallel streams. Use when cutting a release, choosing a semantic version bump, tagging, or writing a changelog.

alfathafp/portofolio-web-design

Refines raw ideas into sharp, actionable concepts through structured divergent and convergent thinking. Use when an idea is still vague, when you need to stress-test assumptions before committing to a plan, or when you want to expand options before converging on one. Triggers on "ideate", "refine this idea", or "stress-test my plan".

alfathafp/portofolio-web-design

Delivers changes incrementally in thin, verifiable slices. Use when implementing any feature or change that touches more than one file, or when picking up the next task from a plan. Use when rolling a change out behind a feature flag, when you're about to write a large amount of code at once, or when a task feels too big to land in one step.

alfathafp/portofolio-web-design

Guides stable API and interface design. Use when designing APIs, module boundaries, or any public interface. Use when creating REST or GraphQL endpoints, defining type contracts between modules, or establishing boundaries between frontend and backend.

相关技能