Communitygithub.com

alfathafp/portofolio-web-design

使用基于令牌的身份验证在 Vercel 上部署和管理项目。当使用 Vercel CLI 但需要访问令牌而非交互式登录时使用——例如“部署到 Vercel”、“设置 Vercel”、“向 Vercel 添加环境变量”。

portofolio-web-design 是什么?

该技能提供了使用令牌认证而非交互式 `vercel login` 来操作 Vercel CLI 的完整指南。它详细说明了如何从环境变量或 `.env` 文件中定位和导出 `VERCEL_TOKEN`,并强调严禁将令牌作为 `--token` 参数传递以保证安全。技能覆盖了多种部署场景:当已有项目 ID 时的快速部署、通过 `vercel link` 进行项目链接的完整部署流程,以及从远程仓库部署。它还管理环境变量、检查部署状态、管理域名,并处理由 Stripe Projects 管理的 Vercel 资源(如升级/降级计划)的变更。技能内嵌了一个清晰的工作协议,确保所有操作(例如默认预览部署、推送前征求用户许可)都安全且用户可感知,并包含针对令牌缺失、认证失败、团队错误和构建失败的故障排除步骤。

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

在你喜欢的 AI 中提问

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

文档

使用令牌的 Vercel CLI

使用 CLI 和基于令牌的身份验证在 Vercel 上部署和管理项目,无需依赖 vercel login。

第一步:定位 Vercel 令牌

在运行任何 Vercel CLI 命令之前,请确定令牌的来源。按顺序处理以下场景:

A) 环境中已设置 VERCEL_TOKEN

printenv VERCEL_TOKEN

如果返回了值,说明已准备就绪。跳至第二步。

B) 令牌在 .env 文件中,变量名为 VERCEL_TOKEN

grep '^VERCEL_TOKEN=' .env 2>/dev/null

如果找到,则导出:

export VERCEL_TOKEN=$(grep '^VERCEL_TOKEN=' .env | cut -d= -f2-)

C) 令牌在 .env 文件中,但变量名不同

查找任何看起来像 Vercel 令牌的变量(Vercel 令牌通常以 vca_ 开头):

grep -i 'vercel' .env 2>/dev/null

检查输出以确定哪个变量持有令牌,然后将其导出为 VERCEL_TOKEN:

export VERCEL_TOKEN=$(grep '^<VARIABLE_NAME>=' .env | cut -d= -f2-)

D) 未找到令牌——请询问用户

如果以上方法均未获得令牌,请询问用户提供。他们可以在 vercel.com/account/tokens 创建 Vercel 访问令牌。


重要: 一旦 VERCEL_TOKEN 作为环境变量导出,Vercel CLI 会原生读取它——不要将其作为 --token 参数传递。将机密信息放在命令行参数中会使其暴露在 shell 历史和进程列表中。

# 错误——令牌在 shell 历史和进程列表中可见
vercel deploy --token "vca_abc123"

# 正确——CLI 从环境中读取 VERCEL_TOKEN
export VERCEL_TOKEN="vca_abc123"
vercel deploy

第二步:定位项目和团队

类似地,检查项目 ID 和团队范围。这允许 CLI 定位正确的项目,而无需 vercel link。

# 检查环境
printenv VERCEL_PROJECT_ID
printenv VERCEL_ORG_ID

# 或检查 .env
grep -i 'vercel' .env 2>/dev/null

如果你有项目 URL(例如 https://vercel.com/my-team/my-project),提取团队 slug:

# 例如:从 "https://vercel.com/my-team/my-project" 中提取 "my-team"
echo "$PROJECT_URL" | sed 's|https://vercel.com/||' | cut -d/ -f1

如果你的环境中同时有 VERCEL_ORG_ID 和 VERCEL_PROJECT_ID,请导出它们——CLI 将自动使用它们,并跳过任何 .vercel/ 目录:

export VERCEL_ORG_ID="<org-id>"
export VERCEL_PROJECT_ID="<project-id>"

注意:VERCEL_ORG_ID 和 VERCEL_PROJECT_ID 必须同时设置——只设置其中一个会导致错误。

CLI 设置

确保 Vercel CLI 已安装且是最新的:

npm install -g vercel
vercel --version

部署项目

除非用户明确要求生产环境,否则始终作为预览部署。根据你已有的信息选择一种方法。

快速部署(已有项目 ID——无需链接)

当环境中设置了 VERCEL_TOKEN 和 VERCEL_PROJECT_ID 时,直接部署:

vercel deploy -y --no-wait

带上团队范围(通过 VERCEL_ORG_ID 或 --scope):

vercel deploy --scope <team-slug> -y --no-wait

生产环境(仅在明确要求时):

vercel deploy --prod --scope <team-slug> -y --no-wait

检查状态:

vercel inspect <deployment-url>

完整部署流程(无项目 ID——需要链接)

当你有令牌和团队但没有预先存在的项目 ID 时使用。

首先检查项目状态

# 项目是否有 git 远程?
git remote get-url origin 2>/dev/null

# 是否已链接到 Vercel 项目?
cat .vercel/project.json 2>/dev/null || cat .vercel/repo.json 2>/dev/null

链接项目

使用 git 远程(推荐):

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

读取 git 远程并连接到匹配的 Vercel 项目。创建 .vercel/repo.json。比普通的 vercel link(通过目录名称匹配)更可靠。

不使用 git 远程:

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

创建 .vercel/project.json。

按名称链接到特定项目:

vercel link --project <project-name> --scope <team-slug> -y

如果项目已链接,请检查 .vercel/project.json 或 .vercel/repo.json 中的 orgId 以验证它是否与目标团队匹配。

链接后部署

A) Git 推送部署——有 git 远程(推荐)

Git 推送会触发自动的 Vercel 部署。

  1. 在推送前询问用户。 未经明确批准,绝不推送。
  2. 提交并推送:
    git add .
    git commit -m "deploy: <更改说明>"
    git push
    
  3. Vercel 自动构建。非生产分支获得预览部署。
  4. 获取部署 URL:
    sleep 5
    vercel ls --format json --scope <team-slug>
    
    在 deployments 数组中找到最新条目。

B) CLI 部署——无 git 远程

vercel deploy --scope <team-slug> -y --no-wait

检查状态:

vercel inspect <deployment-url>

从远程仓库部署(代码未克隆到本地)

  1. 克隆仓库:
    git clone <repo-url>
    cd <repo-name>
    
  2. 链接到 Vercel:
    vercel link --repo --scope <team-slug> -y
    
  3. 通过 git 推送(如果你有推送权限)或 CLI 部署。

关于 .vercel/ 目录

一个已链接的项目有以下两者之一:

  • .vercel/project.json——来自 vercel link。包含 projectId 和 orgId。
  • .vercel/repo.json——来自 vercel link --repo。包含 orgId、remoteName 和一个 projects 映射。

当环境中同时设置了 VERCEL_ORG_ID + VERCEL_PROJECT_ID 时则不需要。

不要在未链接的目录中运行 vercel project inspect 或 vercel link 来检测状态——它们会交互式提示或静默链接作为副作用。vercel ls 是安全的(在未链接的目录中,它默认显示该范围的所有部署)。vercel whoami 在任何地方都是安全的。

管理环境变量

# 为所有环境设置
echo "value" | vercel env add VAR_NAME --scope <team-slug>

# 为特定环境设置(production、preview、development)
echo "value" | vercel env add VAR_NAME production --scope <team-slug>

# 列出环境变量
vercel env ls --scope <team-slug>

# 将环境变量拉取到本地的 .env.local 文件
vercel env pull --scope <team-slug>

# 删除变量
vercel env rm VAR_NAME --scope <team-slug> -y

检查部署

# 列出最近的部署
vercel ls --format json --scope <team-slug>

# 检查特定部署
vercel inspect <deployment-url>

# 查看构建日志(需要 Vercel CLI v35+)
vercel inspect <deployment-url> --logs

# 查看运行时请求日志(默认实时跟踪;添加 --no-follow 获取一次性快照)
vercel logs <deployment-url>

管理域名

# 列出域名
vercel domains ls --scope <team-slug>

# 向项目添加域名——已链接或环境链接的目录(1 个参数)
vercel domains add <domain> --scope <team-slug>

# 添加域名——未链接的目录(需要 <project> 位置参数)
vercel domains add <domain> <project> --scope <team-slug>

Stripe Projects 计划变更

如果此项目由 Stripe Projects 管理。在运行任何付费或破坏性计划变更前请询问用户——升​级会向真实信用卡收费,降级会移除席位。

首先运行 stripe projects status --json 以确认 Vercel 资源的本地名称。以下示例假定使用默认名称(vercel-plan);如果在 stripe projects add 时重命名了,请替换为实际名称。

  • 升级到 Pro: stripe projects add vercel/pro(或 stripe projects upgrade vercel-plan pro)
  • 降级到 Hobby: stripe projects downgrade vercel-plan hobby

Pro 提供的内容

  • 每月 $20 平台费,包含每月 $20 的使用额度。
  • 新项目默认使用 Turbo 构建机器(30 vCPUs,60 GB 内存)——构建速度显著快于 Hobby。
  • 1 个部署席位 + 无限免费查看者席位(只读协作者、预览评论)。
  • 更高的包含分配(每月 1 TB 快速数据传输,1000 万边缘请求)。
  • 可用的付费附加功能:SAML SSO、HIPAA BAA、Flags Explorer、Observability Plus、Speed Insights、Web Analytics Plus。

完整详情:https://vercel.com/docs/plans/pro-plan

工作协议

  • 切勿将 VERCEL_TOKEN 作为 --token 参数传递。 将其导出为环境变量,让 CLI 原生读取。
  • 在询问用户之前先检查环境中的令牌。 首先在当前环境和 .env 文件中查找。
  • 默认使用预览部署。 仅当明确要求时才部署到生产环境。
  • 在推送到 git 前询问。 未经用户批准,绝不提交代码。
  • 不要直接修改 .vercel/ 文件。 CLI 管理此目录。读取它们(例如验证 orgId)是允许的。
  • 不要 curl/获取已部署 URL 来验证。 只需将链接返回给用户。
  • 当结构化输出有助于后续步骤时使用 --format json。
  • 在需要确认的命令中使用 -y 以避免交互式阻塞。

故障排除

令牌未找到

检查环境和任何存在的 .env 文件:

printenv | grep -i vercel
grep -i vercel .env 2>/dev/null

认证错误

如果 CLI 失败并显示 Authentication required:

  • 令牌可能已过期或无效。
  • 验证:vercel whoami(使用环境中的 VERCEL_TOKEN)。
  • 请用户提供新令牌。

错误的团队

验证范围是否正确:

vercel whoami --scope <team-slug>

构建失败

检查构建日志:

vercel inspect <deployment-url> --logs

常见原因:

  • 缺少依赖——确保 package.json 完整且已提交。
  • 缺少环境变量——使用 vercel env add 添加。
  • 框架配置错误——检查 vercel.json。Vercel 会从 package.json 自动检测框架(Next.js、Remix、Vite 等);如果检测错误,请用 vercel.json 覆盖。

CLI 未安装

npm install -g vercel

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

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

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

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.

相关技能