Develop, build, and deploy·续

Build Output records the mode it was built with. When you deploy an existing build, pass the same mode.

Deploy a prebuilt build

Pass --prebuilt to deploy an existing .cloudflare/output/v0/ directory without building. One CI job can build, and another can deploy the restored directory. --prebuilt also skips automatic configuration.

The deploy command must request the mode that Build Output records:

  • When Build Output records a mode, pass exactly that mode with --mode.
  • When Build Output records no mode, do not pass --mode.

Vite builds always record a mode. cf build without --mode records production, so deploy that build with --mode production:

cf build
cf deploy --prebuilt --mode production

Deploy a staging build with the staging mode:

cf build --mode staging
cf deploy --prebuilt --mode staging

Builds through Wrangler record a mode only when you pass --mode to cf build. To check the recorded mode, read buildContext.mode in .cloudflare/output/v0/config.json.

The same rule applies to --prebuilt with cf previews deploy, cf workers versions create, cf workers triggers deploy, and cf workers check. When the modes do not match, the command stops before it uploads anything and prints the --mode value to use.

For a complete pipeline, refer to Use cf in CI.

Upload a version

Upload a Worker Version without deploying it:

cf workers versions create

This command builds and validates the project the same way as cf deploy. It accepts --prebuilt, --mode, --message, --tag, --secrets-file, --dry-run, and --worker. Use --preview-alias <ALIAS> to give the version a preview URL alias.

To send traffic to an uploaded version, create a deployment:

cf workers deployments create --worker example-worker --strategy percentage --versions '[{"version_id":"<VERSION_ID>","percentage":100}]'

Deploy triggers

Apply trigger configuration from Build Output without uploading a new version:

cf workers triggers deploy

This command applies routes, custom domains, the workers.dev setting, cron schedules, Queue consumers, and Workflows. It builds the project unless you pass --prebuilt. It also accepts --mode, --worker, and --dry-run. A dry run sends no API requests.

Deploy a preview

Deploy the project as a Worker Preview:

cf previews deploy

The command builds the project with isPreview set to true, so a function-form cloudflare.config.ts can return preview-specific settings. It then uploads the preview and prints the result as JSON. Previews in cf can change during the beta.

The preview name defaults to the current branch. cf reads the branch from Workers Builds, GitHub Actions, or GitLab CI/CD, and then from Git. On a detached HEAD with no CI branch, pass a name:

cf previews deploy my-feature

The command accepts --mode, --worker, and --prebuilt. With --prebuilt, Build Output must come from a preview build, and the mode rule applies. There is no --dry-run, and the command needs credentials.

The JSON result contains type, version, preview_id, preview_name, preview_slug, preview_urls, deployment_id, and deployment_urls.

Previews do not support Durable Object-managed Containers. cf deploy, cf workers versions create, and cf workers triggers deploy refuse preview Build Output and print the cf previews deploy command to use instead.

Profile Worker startup

Profile the Worker's startup performance locally:

cf workers check

The command builds the project unless you pass --prebuilt. It prints the bundle size and startup timings as JSON, and writes a CPU profile to worker-startup.cpuprofile. Use --outfile <PATH> to choose a different file. The command also accepts --mode and --worker.

The measurement runs on your machine. Use it to find where startup time goes, not to predict startup time on Cloudflare.

Generate types

Generate TypeScript types from cloudflare.config.ts:

cf workers types

The command writes .cloudflare/types/index.d.ts, which contains the Env binding types and the Workers runtime types. Pass --no-include-runtime to leave out the runtime types, or --mode to evaluate the configuration for a named mode.

The Cloudflare Vite plugin writes the same file during development and builds. Run cf workers types in projects that build through Wrangler, or before tsc in a type-check script. Projects created with cf init include a typecheck script that runs cf workers types && tsc.

Local resource data

Add --local to a supported command to run it against a local simulation instead of the Cloudflare API:

cf d1 raw <DATABASE_ID> --sql "SELECT 1" --local
cf r2 objects list --bucket-name <BUCKET_NAME> --local

--local works only for a few resources that local development provides. cf starts a short-lived local runtime for each command, so no dev server needs to be running. Local support covers these commands:

  • cf kv keys get, cf kv keys list, cf kv keys put, and cf kv keys delete
  • cf kv bulk get, cf kv bulk put, and cf kv bulk delete
  • cf d1 raw
  • cf d1 migrations list and cf d1 migrations apply
  • cf r2 objects get, cf r2 objects put, cf r2 objects list, and cf r2 objects bulk-delete
  • cf d1 list, cf kv namespaces list, and cf r2 buckets list

cf d1 query has no local equivalent. Use cf d1 raw instead. A command without a local equivalent fails with This command has no local equivalent. instead of calling the Cloudflare API.

By default, --local keeps its data in a state/v3 directory inside the cf configuration directory. That is ~/.config/cloudflare/state/v3 on Linux and ~/Library/Preferences/cloudflare/state/v3 on macOS. Every project on your machine shares this directory. Pass --persist-to <DIRECTORY> to use <DIRECTORY>/v3 instead. --persist-to works only with --local.

This is not the data your dev server uses. The Cloudflare Vite plugin 2.0 beta keeps development data in the project, under .cloudflare/state/.

Which configuration each command reads

Project commands, such as cf dev, cf build, and cf deploy, run a build tool that loads the whole cloudflare.config.ts, including the Worker and Containers.

Ordinary API commands, such as cf d1 list, read only accountId and complianceRegion from the nearest cloudflare.config.ts in the current directory or a parent directory. A syntax error, import error, or top-level runtime error in that file still stops them. For details, refer to Set account defaults.

API credentials, such as CLOUDFLARE_API_TOKEN, can also come from a .env file in the current directory. Commands that build first, such as cf deploy, load those values after the build finishes. For details, refer to Load credentials from a .env file.

Troubleshooting

No dev server is installed

No Cloudflare dev-server is installed in this project.

cf found no framework that it recognizes and no Cloudflare build tool declared in package.json, for example in an empty directory. To create a project, run cf init.

Dependencies are not installed

In a configured project whose dependencies are not installed, Vite reports that it cannot resolve @cloudflare/vite-plugin, or cf reports that a build tool is declared but not installed. Install dependencies with your package manager, then run the command again.

Arguments are rejected

Arguments cannot currently be forwarded to the detected dev command `npx vite`. Run that command directly with the required arguments.

cf runs the framework's command and forwards only --mode. Set the option in the framework's configuration, or run the framework command directly.

A framework rejects --mode

The detected command `<COMMAND>` does not currently support `--mode`.

Only Vite and Astro accept --mode when cf runs a framework command. Run the command without --mode.

A prebuilt deploy rejects the mode

The Build Output was created with mode "production", but this command did not specify a mode. Rerun with "--mode production".
The Build Output does not record which mode it was created with, but this command requested mode "staging". Rebuild with "--mode staging" before deploying.

Pass exactly the mode that Build Output records, or omit --mode when it records none. Refer to Deploy a prebuilt build.

Build Output is missing

Build Output Specification: no root config found at <PATH>/.cloudflare/output/v0/config.json.

A --prebuilt command found no build. Run cf build first, or restore the complete .cloudflare/output/v0/ directory from your build job.

Preview output reaches a production deploy

This build output is for a Preview. Run cf previews deploy --prebuilt --mode production instead.

The existing Build Output came from cf previews deploy. Run the suggested command to deploy the preview, or run cf build to create production output.

The preview name cannot be determined

We couldn't determine a Preview name from CI or Git.

cf previews deploy found no branch name, for example on a detached HEAD. Pass a name: cf previews deploy <PREVIEW_NAME>.

A local command has no local equivalent

This command has no local equivalent. Re-run without --local to use the Cloudflare API.

The command does not support --local. For D1 queries, use cf d1 raw instead of cf d1 query. Otherwise, run the command without --local.

Was this helpful?

YesNo

On this page

Develop, build, and deploy·续 - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cf/projects/#page","headline":"Develop, build, and deploy","description":"Run, build, and deploy Workers projects with the Cloudflare CLI, including modes, prebuilt deploys, and previews.","url":"https://developers.cloudflare.com/cf/projects/","inLanguage":"en","image":"https://developers.cloudflare.com/cf/projects/og.png?v=08ae0671b2972952","dateModified":"2026-10-17","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Configure Workers projects with a typed cloudflare.config.ts file. title: Programmatic configuration image: https://developers.cloudflare.com/cf/projects/cloudflare-config/og.png?v=b3958a991af163a7


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cf/llms.txt
Use this file to discover all available pages before exploring further.