agentleFS
CloudflareKnown publishercloudflare/workers-sdk/packages/vite-plugin-cloudflare/AGENTS.md

workers-sdk / vite-plugin-cloudflare

AGENTS.md4.6k starsChanged 6 months agoApache-2.0View on GitHub

Vite plugin for Cloudflare Workers development. Exports cloudflare() plugin factory from src/index.ts. ESM-only output. bin/cf-vite is an experimental, internal delegate binary spawned by Cloudflare's "cf-dev" parent process — NOT part of the plugin's public API and not meant for direct end-user invocation. It is the sibling of wrangler's cf-wrangler binary, and the two MUST keep a shared spawn contract so the parent can drive either impl interchangeably. - Verb dispatch. cf-vite <verb> [flags]. dev and build are the verbs today;…

  • Reads credentials

Trending

Quiet since August.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 1 mentionJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the cloudflare/workers-sdk repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about cloudflare/workers-sdk

The biggest 5 of 17 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 17

Talked about on GitHub, Bluesky and Hacker News (17 times).

On GitHub · 14

9 more on GitHub

The file

We split this AGENTS.md into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Only package using tsdown as build tool

    line 19
  2. Very specific:

    Do NOT add flags here unless cf-wrangler grows them too.

    line 39
  3. Very specific:

    No named imports from "wrangler" — must use import * as wrangler from "wrangler" (namespace import only, enforced by eslint)

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md — vite-plugin-cloudflare

OVERVIEW

Vite plugin for Cloudflare Workers development. Exports cloudflare() plugin factory from src/index.ts. ESM-only output.

STRUCTURE

  • src/index.ts — Plugin factory (uses top-level await for assertWranglerVersion())
  • src/cf-vite.ts — cf-vite delegate binary entry (see below)
  • bin/cf-vite — shebang shim that dynamic-imports dist/cf-vite.mjs
  • src/workers/ — 4 internal worker entries: asset-worker, router-worker, runner-worker, vite-proxy-worker
  • playground/ — ~47 playground apps, each a workspace member (nested workspace under this package)
  • e2e/ — E2E tests with Playwright
  • __tests__/ — Unit tests use .spec.ts naming

BUILD

  • Only package using tsdown as build tool
  • Outputs ESM (.mjs) to dist/index.mjs
  • src/cf-vite.ts is a second top-level tsdown entry, bundled to dist/cf-vite.mjs (no dts)
  • Also bundles 4 internal worker scripts from src/workers/*/index.ts as separate neutral-platform outputs to dist/workers/

cf-vite DELEGATE BINARY (experimental / internal)

bin/cf-vite is an experimental, internal delegate binary spawned by Cloudflare's "cf-dev" parent process — NOT part of the plugin's public API and not meant for direct end-user invocation. It is the sibling of wrangler's cf-wrangler binary, and the two MUST keep a shared spawn contract so the parent can drive either impl interchangeably.

  • Verb dispatch. cf-vite <verb> [flags]. dev and build are the verbs today; future verbs (deploy) follow the same shape. Unknown/missing verbs exit 2 (this doubles as the parent's version-detection signal — no JSON handshake).
  • Shared flag vocabulary (dev). For dev, only --mode, --port, --host, --local are accepted, mirroring cf-wrangler exactly. Parsed with node:util.parseArgs strict mode → unknown flags exit 2. Do NOT add flags here unless cf-wrangler grows them too. (There is no --config flag: the wrangler config is discovered by cloudflare() itself.)
  • build cf-vite build runs Vite's full multi-environment app build via createBuilder().buildApp() (NOT the legacy single-environment build() helper, which would skip the plugin's worker/build-output orchestration — mirrors Vite's own vite build CLI). It accepts only --mode (--port/--host/--local don't apply to a build and exit 2). Preview build context is supplied through CLOUDFLARE_PREVIEW_BUILD, which also works when a framework runs Vite as part of its own build command.
  • Build Output Specification forced for every verb. main() sets CLOUDFLARE_VITE_FORCE_BUILD_OUTPUT unconditionally (before Vite loads the user's config), enabling experimental.newConfig + experimental.newConfig.cfBuildOutput (overriding plugin config), which requires a cloudflare.config.ts at the project root. The env var name and read logic live in build-output-env.ts (FORCE_BUILD_OUTPUT_ENV_VAR / isForcedBuildOutput()), shared by the two read sites that MUST agree: index.ts (selects the build-output plugin at construction) and resolvePluginConfig. Both read directly from process.env (NOT Vite's loadEnv), since index.ts runs before Vite resolves a root/mode and this is an internal bridge, not a .env-file knob.
  • dev cf-vite dev boots Vite via createServer() against the user's own vite.config.ts (which must include cloudflare()). Plugin-owned flags are bridged via env vars the plugin already reads (--local → CLOUDFLARE_VITE_FORCE_LOCAL); Vite-owned flags go through inline config (--port/--host → server.*, --mode → mode).
  • --local forces remote bindings off. There is no plugin env knob for remoteBindings other than CLOUDFLARE_VITE_FORCE_LOCAL, which resolvePluginConfig in plugin-config.ts honours by overriding the remoteBindings config option. Keep that override in sync if the flag semantics change.
  • Hotkeys differ by design. cf-vite uses Vite's own bindCLIShortcuts (h/r/q/…), not wrangler's hotkey set. The parent process should not assume identical hotkey UX across delegates.
  • Exit codes. 0 graceful, 2 unknown verb / argv parse error, 130 SIGINT, 143 SIGTERM.

CONVENTIONS

  • No named imports from "wrangler" — must use import * as wrangler from "wrangler" (namespace import only, enforced by eslint)
  • Top-level await in entry — only possible because ESM-only
  • Playground directory worker-♫/ has unicode in name (intentional)

TESTING

  • Unit tests: .spec.ts in __tests__/
  • E2E tests: .test.ts in e2e/, own vitest config
  • Playground tests: Playwright-based, tested across Vite 6/7/8 in CI
  • Playground request helpers (playground/__test-utils__/responses.ts):
    • getTextResponse() / getJsonResponse() issue a request with browser navigation headers (Sec-Fetch-Mode: navigate et al), which the asset and router workers branch on. Default to these.
    • They use undici's low-level request() rather than fetch() deliberately. The Fetch spec requires implementations to set Sec-Fetch-Mode from the request's mode ("append the Fetch metadata headers"), so fetch() overwrites whatever the caller passed with cors before the request leaves the process (appendFetchMetadata in undici). Sec-Fetch-Dest/-Site/-User are unimplemented there, so they survive — which is why only Sec-Fetch-Mode breaks and it is easy to miss. That one decides whether the asset worker applies not_found_handling.
    • This is permanent, not a bug to wait out: no Fetch-based API can send Sec-Fetch-Mode: navigate, and fetch(url, { mode: "navigate" }) is rejected by the Request constructor. Do not "simplify" these back to fetch(); spa-with-api's "via getTextResponse()" test exists to catch exactly that regression (it is the only playground whose compat date enables SEC_FETCH_MODE_NAVIGATE_HEADER_PREFERS_ASSET_SERVING).
    • getResponse() drives a real page.goto() and returns a Playwright Response. Only use it when the assertion needs the browser. Anything routed through Playwright can outlive a timed-out test and surface as an unhandled rejection, which fails the whole run rather than one test.
    • WAIT_FOR_OPTIONS (playground/__test-utils__/index.ts) must stay comfortably below the test timeout, otherwise vi.waitFor() never gets to report the assertion that was actually failing.
  • playground/vitest.config.e2e.ts inherits the repo-wide timeouts and retry: 1 from the root vitest.shared.ts. It spreads configShared.test rather than using mergeConfig(), which concatenates arrays and would silently enable the shared default reporter alongside dot.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.