Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

Workers Vite Plugin: Local Development, Configuration, and Full-Stack Frameworks

How Cloudflare's Vite plugin runs Workers in workerd, configures Wrangler, auxiliary Workers, TanStack Start, static assets, and local dev.

This page summarizes Cloudflare’s documentation on the Cloudflare Vite plugin (@cloudflare/vite-plugin): using Vite’s dev server and build pipeline while your Worker runs locally in workerd, the open-source Workers runtime. It covers when to choose the plugin over Wrangler alone, Worker configuration (files and programmatic options), Vite environments for SSR and React Server Components (RSC), auxiliary Workers, framework setups (especially TanStack Start), static assets, and local persistence.

When you use @cloudflare/vite-plugin, you can use Vite’s local development server and build tooling, while ensuring that while developing, your code runs in workerd, the open-source Workers runtime.

— Cloudflare, The Cloudflare Vite plugin is now Generally Available

Cloudflare Vite plugin vs wrangler dev: when to use which

Section titled “Cloudflare Vite plugin vs wrangler dev: when to use which”

The plugin fits projects that already use Vite or benefit from Vite’s transformations, Hot Module Replacement (HMR), and plugin ecosystem. Wrangler fits a direct CLI workflow when Vite is not part of the stack.

Capability or workflow Wrangler Cloudflare Vite plugin
Standalone JavaScript or TypeScript Workers Supported Supported
Full-stack and backend Workers Supported Supported
Local binding simulations via Miniflare Supported Supported
Remote bindings Supported Supported
Multi-Worker development Supported Supported
Frontend and SSR frameworks Framework build output Integrates with Vite-powered frameworks
Build pipeline Wrangler bundler or custom build Vite transformations, HMR, plugins
Deployment Supported Use Wrangler after vite build
Rust Workers Supported Not supported
Python Workers Use pywrangler Not supported

Use the Cloudflare Vite plugin when your project already uses Vite or would benefit from its build pipeline. Vite is valid for standalone backend Workers, not only frontend applications.

— Cloudflare, Choosing between Wrangler & Vite

Use wrangler dev when the project does not use Vite. Both tools support remote bindings so the Worker runs locally while selected bindings reach deployed Cloudflare resources. For configuration differences when moving an existing project, see Migrating from wrangler dev.

@cloudflare/vite-plugin setup: minimal Vite config

Section titled “@cloudflare/vite-plugin setup: minimal Vite config”

The cloudflare() plugin belongs in the Vite plugins array and accepts an optional PluginConfig. See the API reference.

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

For a standalone Worker from scratch, Get started shows viteEnvironment: { name: "worker" }, a matching environments.worker block, and scripts such as dev, build, preview, and deploy (vite build && wrangler deploy). The plugin looks for wrangler.jsonc, wrangler.json, or wrangler.toml in the project root unless you rely on defaults or programmatic config.

Vite 7: The plugin supports Vite 7; minimum Node.js versions for Vite 7 are 20.19 and 22.12. Vite 6 remains supported (changelog).

Wrangler config with the Vite plugin: input, output, and ignored fields

Section titled “Wrangler config with the Vite plugin: input, output, and ignored fields”

With the plugin, your Worker config file (for example wrangler.jsonc) is input; the build writes a separate output configuration that references build artifacts and is used for preview and deployment. After vite build, wrangler deploy or vite preview locates that output file automatically.

With the Cloudflare Vite plugin, your Worker config file (for example, wrangler.jsonc) is the input configuration and a separate output configuration is created as part of the build.

— Cloudflare, Migrating from wrangler dev

Several Wrangler fields are ignored or replaced by Vite (warnings suggest alternatives): build-related options like tsconfig, rules, build, no_bundle, find_additional_modules, base_dir, and preserve_file_names are handled by Vite; define, alias, and minify map to Vite’s define, resolve.alias, and build.minify; local dev settings map to Vite server options.

Optional Wrangler file for assets-only static sites

Section titled “Optional Wrangler file for assets-only static sites”

For assets-only static sites, a Wrangler file is optional. If none is found, the plugin generates defaults: name from package.json or the directory name, compatibility_date from your installed Miniflare version.

When using the Cloudflare Vite plugin to build and deploy Workers, a Wrangler configuration file is now optional for assets-only (static) sites.

— Cloudflare, Wrangler config is optional when using Vite plugin

Single-page applications still need assets.not_found_handling set appropriately for SPA routing (see the same changelog). Vite-powered SPAs may use the plugin for a Vite-native dev experience (SPA local development).

Programmatic Worker config in vite.config: merge rules and limits

Section titled “Programmatic Worker config in vite.config: merge rules and limits”

The config option defines or overrides Worker settings in Vite without a separate Wrangler file, or merges on top of a loaded file. It runs after any config file is loaded.

The Vite plugin’s new config option accepts either a partial configuration object or a function that receives the current configuration and returns overrides.

— Cloudflare, Configure Workers programmatically using the Vite plugin

Programmatic configuration is aimed mainly at framework and plugin authors; end users normally use Wrangler config files. Values set via config are not included when running wrangler types or resource CLI commands such as wrangler kv or wrangler d1.

You cannot define Cloudflare environments via config (they resolve before this option applies). Merging uses defu: objects merge recursively, arrays concatenate (config first), primitives from config win, and undefined does not override.

Patterns:

  • Object merge — partial Wrangler-shaped properties alongside defaults or file config.
  • Function returning overrides — receive current config, return an object to merge.
  • In-place mutation — mutate userConfig (for example delete flags); do not return a value from the function.

Auxiliary Workers can use config inside auxiliaryWorkers for multi-Worker setups without per-Worker files, and may inherit from the entry Worker via entryWorkerConfig in the config function’s second argument (Programmatic configuration).

viteEnvironment and childEnvironments: SSR and React Server Components

Section titled “viteEnvironment and childEnvironments: SSR and React Server Components”

The Vite Environment API (Vite 6+) is what lets the plugin run code in the Workers runtime. For TanStack Start and React Router v8, assign the Worker to the ssr environment:

cloudflare({ viteEnvironment: { name: "ssr" } })

If you are using the Cloudflare Vite plugin with TanStack Start or React Router v8, then your Worker is used for server-side rendering and tightly integrated with the framework. To support this, you should assign it to the ssr environment by setting viteEnvironment.name in the plugin config.

— Cloudflare, Vite Environments

For RSC with @vitejs/plugin-rsc, use childEnvironments so the parent environment can import from a separate module graph:

cloudflare({
viteEnvironment: {
name: "rsc",
childEnvironments: ["ssr"],
},
})

See Improved React Server Components support. Note for React Router with the plugin: SPA mode and prerendering are not currently supported (React Router framework guide); use the React template and React Router as a library for SPA mode.

Auxiliary Workers: configPath, config, and Vite 7

Section titled “Auxiliary Workers: configPath, config, and Vite 7”

Auxiliary Workers are extra Workers invoked via service bindings from the entry Worker. In full-stack framework projects they ship beside framework build output in the build output directory. This requires Vite 7 or above.

Auxiliary Workers are additional Workers that can be called via service bindings from your main (entry) Worker.

— Cloudflare, Use auxiliary Workers alongside full-stack frameworks

Each auxiliary Worker needs configPath, config, or both on AuxiliaryWorkerConfig. CLOUDFLARE_VITE_WRANGLER_CONFIG_PATH applies only to the entry Worker, not auxiliary Workers (API).

Example with a framework and configPath:

cloudflare({
viteEnvironment: { name: "ssr" },
auxiliaryWorkers: [{ configPath: "./wrangler.aux.jsonc" }],
})

TanStack Start on Workers: scaffold, migrate, prerender, and custom entry

Section titled “TanStack Start on Workers: scaffold, migrate, prerender, and custom entry”

Official support includes new projects via create-cloudflare with --framework=tanstack-start (TanStack Start, changelog).

Existing apps: install @cloudflare/vite-plugin and wrangler, add cloudflare({ viteEnvironment: { name: "ssr" } }) with tanstackStart() and @vitejs/plugin-react, remove another deployment adapter (such as nitro()), and add wrangler.jsonc with main: @tanstack/react-start/server-entry, nodejs_compat, and a current compatibility_date. Rsbuild-based TanStack Start projects must migrate to Vite first.

Static prerendering enables build-time HTML with build-time env vars and bindings (changelog):

tanstackStart({ prerender: { enabled: true } })

Requires @tanstack/react-start v1.138.0 or later. Prerendering uses local env, secrets, and binding storage; use remote bindings for production-like data. In CI, set CLOUDFLARE_INCLUDE_PROCESS_ENV=true and provide variables as needed (TanStack Start — Prerendering data sources).

A custom server entry (src/server.ts) can add Queues, Cron Triggers, and Durable Object exports while delegating fetch to @tanstack/react-start/server-entry; run wrangler types (cf-typegen) before adding TypeScript entrypoints.

Wrangler can auto-detect TanStack Start and generate config when you run wrangler deploy without an existing Wrangler file (TanStack Start).

Static assets in Worker code: Vite imports and ASSETS

Section titled “Static assets in Worker code: Vite imports and ASSETS”

The plugin supports Vite static asset handling in Worker code and the frontend: URL imports, string imports, public directory imports, and inlining. URL imports in the Worker are moved to the client build output automatically (Enhanced support for static assets).

import myImage from "./my-image.png";
export default {
async fetch(request, env) {
const response = await env.ASSETS.fetch(new URL(myImage, request.url));
const modifiedResponse = new Response(response.body, response);
modifiedResponse.headers.append("my-header", "imported-asset");
return modifiedResponse;
},
};

Details: Static Assets in the Vite plugin reference. The plugin may add assets to generated deployment configuration when input Wrangler config omits them—affecting frameworks like TanStack Start and Cloudflare Access behavior with static assets and internal router Workers.

Local data directory: persistState and Wrangler alignment

Section titled “Local data directory: persistState and Wrangler alignment”

Local persistence for Miniflare-backed dev can be customized with persistState.path in the Vite plugin:

cloudflare({
persistState: { path: "./my-custom-directory" },
})

To share state between Wrangler and the Vite plugin, point both at the same persistence path (Adding local data).

Containers can run alongside the Worker during local development with the Vite plugin; previously that was limited to Wrangler as the dev server (Develop locally with Containers).

  • Expecting wrangler kv / wrangler d1 or wrangler types to see inline config in vite.config — they use Wrangler config files, not the Vite config option.
  • Leaving redundant Wrangler build fields (build, rules, etc.) instead of Vite equivalents — expect console warnings (Migrating from wrangler dev).
  • Using auxiliary Workers with full-stack frameworks on Vite 6 — requires Vite 7+.
  • SPAs without assets.not_found_handling for SPA routing when relying on generated assets-only defaults.
  • Assuming ctx.access propagates through service bindings or to user Workers behind static-asset routers (Cloudflare Access).
  • Running cf init . in a project that already has wrangler.toml / wrangler.json(c) — automatic setup can ignore Wrangler config; use cf migrate instead (Deploy your first Worker).

For adapting an existing Vite React app with a Worker API route, see the Tutorial — React SPA with an API (client and server HMR without losing UI state). Agents SDK projects may also stack agents/vite with cloudflare() for TC39 decorator transforms when using Vite 8’s Oxc (Agents configuration).

  1. Run vite dev and confirm the app serves locally with Workers bindings behaving as expected (Get started).
  2. Run vite build, then vite preview or wrangler deploy, and confirm deployment uses the build output Wrangler config described in Migrating from wrangler dev.
  3. For TypeScript custom entrypoints (for example TanStack Start), run wrangler types via your cf-typegen script (TanStack Start).
  4. Compare your workflow needs against Choosing between Wrangler & Vite if local behavior differs from expectations.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.