Develop, build, and deploy
Last updated Oct 17, 2026
cf develops, builds, and deploys Workers projects with the same CLI that manages the rest of your Cloudflare account. To create a project, follow Deploy your first Worker.
Configure the project with cloudflare.config.ts. Builds write Build Output to .cloudflare/output/v0/.
How cf runs your project
cf does not run a dev server or bundler itself. For cf dev, cf build, and every other command that builds first, cf hands the work to one of these tools:
- The framework's own command. When
cfdetects a supported framework, it runs that framework's dev or build command through your package manager. In a Vite project, including a project created withcf init, that isviteorvite build, for examplenpx vite buildwith npm. - An installed Cloudflare build tool. Otherwise,
cfuses the Cloudflare build tool declared in the project'spackage.json. That is the Cloudflare Vite plugin, or Wrangler 4.136.0 or later when the Vite plugin is not declared.
cf uses the Cloudflare Vite plugin 2.0 beta (@cloudflare/vite-plugin@beta), which does not depend on Wrangler. Wrangler builds projects that declare it without the Vite plugin, such as projects that cf migrate converts with the Wrangler bundler and static sites that automatic configuration sets up. These projects keep build settings, such as the static assets directory, in a generated wrangler.config.ts file. That file can change during the beta.
cf does not run your package.json scripts. If your build script runs extra steps, such as tsc -b && vite build, then cf build and cf deploy skip them. Chain those steps with cf build in your own script instead:
package.jsonjson
{
"scripts": {
"build": "tsc -b && cf build"
}
}
When cf runs a framework command, it forwards --mode and rejects other arguments. For example, cf dev --port 8788 fails in a Vite project. Set the option in the framework's configuration, such as server.port in vite.config.ts, or run the framework command directly. When cf uses an installed build tool instead, cf dev forwards extra arguments to it, and the tool rejects arguments it does not support. cf build accepts only --mode.
Automatic configuration
When a project has no cloudflare.config.ts, cf tries to detect its framework and set the project up for Cloudflare before it continues. This automatic configuration runs from these commands:
cf devandcf buildcf deploy, includingcf deploy --dry-runcf previews deploycf workers versions create,cf workers triggers deploy, andcf workers checkcf init
A project counts as configured only when cloudflare.config.ts exists in the directory where you run the command. Passing --prebuilt skips automatic configuration.
In a terminal, cf shows the planned changes and asks before it applies them. Without a terminal, or in CI, it applies the changes and installs packages without asking. Run cf init . locally before you set up CI. It configures an existing project without building it. Review the changes and commit them. For the list of changes, refer to Start from an existing project.
Wrangler projects
Automatic configuration does not read Wrangler configuration files. In a project that has wrangler.jsonc, wrangler.json, or wrangler.toml but no cloudflare.config.ts, do not run cf init ., cf dev, cf build, cf deploy, or another command that builds.
In a framework or static-assets project, cf writes a new cloudflare.config.ts that ignores the Wrangler configuration, including its entrypoint and bindings. In a Worker project without a detected framework, the command fails with an error such as cloudflare.config.ts is required when --experimental-new-config is enabled. Convert the project with cf migrate first. Refer to Migrate a Wrangler project.
Start development
Start the project's development server:
cf dev
The dev server prints its local URL. Append /cdn-cgi/local/explorer to that URL to open Local Explorer. Use it to inspect local binding data, view logs and traces, and test Cron Triggers with a chosen cron expression and scheduled time.
Build
Build the project:
cf build
After the build finishes, cf reads and validates .cloudflare/output/v0/. cf build does not upload anything and does not need credentials.
Deploy
cf deploy builds the project, validates Build Output, resolves your credentials and account, uploads a new Worker Version, and deploys it:
cf deploy
Sign in with cf auth login, or set CLOUDFLARE_API_TOKEN, before you deploy. For details, refer to Sign in.
cf deploy can provision missing resources for bindings that omit resource identifiers. It does not write provisioned identifiers back to cloudflare.config.ts.
cf deploy accepts these options:
| Option | Purpose |
|---|---|
--dry-run |
Builds and validates the Worker without uploading it |
--message <TEXT> |
Records a message on the Worker Version |
--tag <TAG> |
Records a tag on the Worker Version |
--secrets-file <PATH> |
Uploads secrets from a JSON or .env format file with the version |
--dispatch-namespace <NAMESPACE> |
Deploys a Workers for Platforms user Worker to that dispatch namespace |
--containers-rollout <STRATEGY> |
Sets the Container rollout strategy: immediate, gradual, or none |
--worker <NAME> |
Selects a Worker from Build Output instead of the default Worker |
--prebuilt |
Deploys existing Build Output without building |
--dry-run sends no API requests and needs no credentials, so you can validate a project before you sign in. In a project without cloudflare.config.ts, it still runs automatic configuration first, which can install packages and change files.
cf deploy --dry-run
cf deploy --message "Fix header parsing" --tag v1.2.0
Modes
A mode selects which configuration a function-form cloudflare.config.ts returns. Pass it with --mode or -m:
cf dev --mode staging
cf build -m staging
cf deploy --mode staging
When you omit --mode, the Cloudflare Vite plugin uses development for cf dev and production for builds. Builds through Wrangler and API commands leave the mode undefined. For the full list, refer to Select a mode.
When cf runs a framework's own command, only Vite and Astro accept --mode. Other framework commands fail with an error. Refer to A framework rejects --mode.
This configuration deploys a separate staging Worker with its own API origin:
Select a highlighted line to show its type and description below it.
cloudflare.config.ts
Expand allCopy
import { bindings, defineConfig } from "cf/config";
import * as entrypoint from "./src/index.ts" with { type: "cf-worker" };
<details>
<summary>export default defineConfig(({ mode }) => { (defineConfig, mode reference)</summary>
<code>defineConfig</code>Function<a href="#modes-config-defineconfig">Link to defineConfig</a>
<code>defineConfig<T extends ConfigInput<CloudflareConfig>>(config: T): T;</code>
Defines the default export of <code>cloudflare.config.ts</code>. Pass a configuration object, a promise that resolves to one, or a function that receives the config context (<code>isPreview</code> and <code>mode</code>) and returns either.
<details>
<summary>Options (4)</summary>
<dl>
<dt><code>accountId?: string</code></dt> <dd>This is the ID of the account associated with your zone. It can also be specified through the <code>CLOUDFLARE_ACCOUNT_ID</code> environment variable.</dd>
<dt><code>complianceRegion?: "public" | "fedramp-high"</code></dt> <dd>The compliance boundary in which commands should operate. When omitted, this can be supplied through <code>CLOUDFLARE_COMPLIANCE_REGION</code>.</dd>
<dt><code>worker?: ConfigInput<WorkerConfig></code></dt> <dd>The Worker defined by this configuration.</dd>
<dt><code>containers?: ConfigInput<ContainerConfig>[]</code></dt> <dd>Container applications defined by this configuration.</dd></dl></details>
<code>mode</code>Context value<a href="#modes-config-defineconfig">Link to mode</a>
<code>mode: string | undefined</code>
The mode the config is being evaluated in. Set via the <code>--mode</code> CLI flag. In Vite the mode defaults to <code>development</code> in <code>vite dev</code> and <code>production</code> in <code>vite build</code> (<a href="https://vite.dev/guide/env-and-mode.html#modes">more info</a>). In Wrangler the mode defaults to <code>undefined</code>.
</details>
const isStaging = mode === "staging";
return {
<details>
<summary>worker: { (worker reference)</summary>
<code>worker</code>Optional<a href="#modes-config-cloudflareconfig-worker">Link to worker</a>
<code>worker?: ConfigInput<WorkerConfig></code>
The Worker defined by this configuration.
</details>
<details>
<summary>name: isStaging ? "example-worker-staging" : "example-worker", (name reference)</summary>
<code>name</code>Required<a href="#modes-config-workerconfig-name">Link to name</a>
<code>name: string</code>
The name of your Worker.
</details>
<details>
<summary>entrypoint, (entrypoint reference)</summary>
<code>entrypoint</code>Optional<a href="#modes-config-workerconfig-entrypoint">Link to entrypoint</a>
<code>entrypoint?: string | WorkerModule</code>
The entrypoint module that will be executed. May be either a path string (e.g. <code>"./src/index.ts"</code>) or a module namespace imported with the <code>cf-worker</code> import attribute.
</details>
<details>
<summary>compatibilityDate: "<COMPATIBILITY_DATE>", (compatibilityDate reference)</summary>
<code>compatibilityDate</code>Required<a href="#modes-config-workerconfig-compatibilitydate">Link to compatibilityDate</a>
<code>compatibilityDate: string</code>
A date in the form yyyy-mm-dd, which will be used to determine which version of the Workers runtime is used. More details at <a href="https://developers.cloudflare.com/workers/configuration/compatibility-dates">https://developers.cloudflare.com/workers/configuration/compatibility-dates</a>
</details>
<details>
<summary>env: { (env reference)</summary>
<code>env</code>Optional<a href="#modes-config-workerconfig-env">Link to env</a>
<code>env?: Record<string, Binding | false | null | undefined></code>
Bindings exposed on the Worker's <code>env</code> object. Construct entries with <code>bindings.kv(...)</code>, <code>bindings.r2(...)</code>, etc. Entries set to <code>false</code>, <code>null</code>, or <code>undefined</code> are omitted, which allows bindings to be included conditionally.
</details>
<details>
<summary>API_ORIGIN: bindings.text( (text reference)</summary>
<code>text</code>Builder<a href="#modes-config-bindings-text-default">Link to text</a>
<code>text<T$1 extends string>(value: T$1): TextBinding<T$1>;</code>
Inline string value made available to the Worker on <code>env</code> under the binding name. For reference, see <a href="https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables">https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables</a>
</details>
isStaging
? "https://staging-api.example.com"
: "https://api.example.com",
),
},
},
};
});
Return one complete configuration for each mode. Programmatic configuration does not merge environment blocks the way Wrangler environments do. A mode deploys a separate Worker only when it returns a different name.
