Skip to content
Cloudflare Docs

API

cloudflare()

The cloudflare plugin should be included in the Vite plugins array:

vite.config.ts
import { defineConfig } from "vite";
import { cloudflare } from "@cloudflare/vite-plugin";
export default defineConfig({
plugins: [cloudflare()],
});

It accepts an optional PluginConfig parameter.

interface PluginConfig

  • configPath string optional

    An optional path to your Worker config file. By default, a wrangler.jsonc, wrangler.json, or wrangler.toml file in the root of your application will be used as the Worker config.

    For more information about the Worker configuration, see Configuration.

  • config Partial<WorkerConfig> | ((config: WorkerConfig) => Partial<WorkerConfig> | void) optional

    Customize or override Worker configuration programmatically. Accepts a partial configuration object or a function that receives the current config.

    Applied after any config file loads. Use it to override values, modify the existing config, or define Workers entirely in code.

    See Programmatic configuration for details.

  • viteEnvironment { name?: string } optional

    Optional Vite environment options. By default, the environment name is the Worker name with - characters replaced with _. Setting the name here will override this. A typical use case is setting viteEnvironment: { name: "ssr" } to apply the Worker to the SSR environment.

    See Vite Environments for more information.

  • persistState boolean | { path: string } optional

    An optional override for state persistence. By default, state is persisted to .wrangler/state. A custom path can be provided or, alternatively, persistence can be disabled by setting the value to false.

  • inspectorPort number | false optional

    An optional override for debugging your Workers. By default, the debugging inspector is enabled and listens on port 9229. A custom port can be provided or, alternatively, setting this to false will disable the debugging inspector.

    See Debugging for more information.

  • auxiliaryWorkers Array<AuxiliaryWorkerConfig> optional

    An optional array of auxiliary Workers. Auxiliary Workers are additional Workers that are used as part of your application. You can use service bindings to call auxiliary Workers from your main (entry) Worker. All requests are routed through your entry Worker. During the build, each Worker is output to a separate subdirectory of dist.

interface AuxiliaryWorkerConfig

Auxiliary Workers require a configPath, a config option, or both.

  • configPath string optional

    The path to your Worker config file. This field is required unless config is provided.

    For more information about the Worker configuration, see Configuration.

  • config Partial<WorkerConfig> | ((config: WorkerConfig) => Partial<WorkerConfig> | void) optional

    Customize or override Worker configuration programmatically. When used without configPath, this allows defining auxiliary Workers entirely in code.

    See Programmatic configuration for usage examples.

  • viteEnvironment { name?: string } optional

    Optional Vite environment options. By default, the environment name is the Worker name with - characters replaced with _. Setting the name here will override this.

    See Vite Environments for more information.