Skip to content

Vercel Integration: Environment variables explained

Last edited: 8/12/2026

Vercel 有三个环境,它们对应部署生命周期的不同阶段:

🌐 Vercel has three environments, which map to different stages of the deployment lifecycle:

  • 生产 用于配置为生产分支的分支(通常是 main)。从该分支的部署会直接上线到网站。
  • 预览 用于所有其他 Git 分支,包括拉取请求、功能分支,以及像 staging 这样的持久分支。如果你部署了一个 staging 分支,它仍然会在预览环境下运行,除非你在 Vercel 中明确创建一个独立环境并将该分支映射到该环境。
  • 开发 仅用于通过 Vercel CLI (vercel dev) 本地开发。它允许你的本地环境从 Vercel 拉取环境变量,但不适用于 Git 分支或平台上的部署。

创建一个预演环境 #

🌐 Creating a staging environment

在 Hobby 计划中,预发布环境是通过将 Preview 环境变量限定到某个分支来实现的。在 Pro 计划中,预发布可以配置为一个独立的环境,拥有自己的设置。

🌐 On the Hobby plan, staging is implemented by scoping Preview environment variables to a branch. On the Pro plan, staging can be configured as a dedicated environment with its own settings.

你可以创建一个专用环境(Vercel Pro):

🌐 You can create a dedicated environment (Vercel Pro):

  1. 前往 ProjectSettingsEnvironments
  2. 点击 Create Environment
  3. 把它命名为 staging
  4. 启用 Branch Tracking 并选择 staging 分支
  5. 为此环境添加环境变量

通过这种设置,staging 分支会部署到它自己的环境,并且与 Preview 和 Production 完全分开。

🌐 With this setup, the staging branch deploys to its own environment and is fully separate from Preview and Production.