You can create a Preview for a new or existing Worker. You do not need to deploy a Worker to production before creating its first Preview.
Worker Previews requires Wrangler 4.135.0 or later. Update the project dependency because project commands do not use a newer global installation.
npm i -D wrangler@latestyarn add -D wrangler@latestpnpm add -D wrangler@latestbun add -d wrangler@latestAdd a previews block to your Wrangler configuration file. Top-level settings define production, and the previews block defines Preview settings. The previews block can be empty if your Preview does not need separate settings.
{
// ...
"vars": {
"ENVIRONMENT": "production"
},
// ...
"previews": {
// ...
"vars": {
"ENVIRONMENT": "preview"
}
// ...
}
}[vars]
ENVIRONMENT = "production"
[previews.vars]
ENVIRONMENT = "preview"To determine which settings belong at the top level or in previews, refer to What goes in the previews block.
Settings that you add or import in the dashboard must also be copied to your Wrangler configuration file.
Run the same Preview command locally or in your existing CI workflow:
npx wrangler previewyarn wrangler previewpnpm wrangler previewThe Preview name defaults to your current Git branch. To choose a name, add --name <PREVIEW_NAME>.
To post Preview URLs automatically to pull requests or merge requests, connect your Git repository and use Workers Builds. New Workers use Worker Previews by default. If an existing Worker already uses Workers Builds, complete the one-time setup.
A successful deployment returns a Preview URL that always points to the latest changes. It also returns a Unique Deployment URL for each deployment, so you can access earlier versions in the Preview's deployment history.
- Configuration - Configure variables, secrets, bindings, and Previews Base.
- Resources and isolation - Decide which resources to share or isolate.
- Limitations - Review current support gaps and workarounds.
- Examples - Add Preview deployments to CI.