70bf21e064
Handle Changesets / Handle Changesets (push) Waiting to run
Semgrep OSS scan / semgrep-oss (push) Waiting to run
Deploy (to testing) and Test Playground Preview Worker / Deploy Playground Preview Worker (testing) (push) Has been skipped
Deploy Workers Shared Staging / Deploy Workers Shared Staging (push) Failing after 0s
Prerelease / build (push) Has been skipped
4.5 KiB
4.5 KiB
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-levelawaitforassertWranglerVersion())src/cf-vite.ts—cf-vitedelegate binary entry (see below)bin/cf-vite— shebang shim that dynamic-importsdist/cf-vite.mjssrc/workers/— 4 internal worker entries:asset-worker,router-worker,runner-worker,vite-proxy-workerplayground/— ~47 playground apps, each a workspace member (nested workspace under this package)e2e/— E2E tests with Playwright__tests__/— Unit tests use.spec.tsnaming
BUILD
- Only package using
tsdownas build tool - Outputs ESM (
.mjs) todist/index.mjs src/cf-vite.tsis a second top-level tsdown entry, bundled todist/cf-vite.mjs(no dts)- Also bundles 4 internal worker scripts from
src/workers/*/index.tsas separate neutral-platform outputs todist/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].devandbuildare the verbs today; future verbs (deploy) follow the same shape. Unknown/missing verbs exit2(this doubles as the parent's version-detection signal — no JSON handshake). - Shared flag vocabulary (
dev). Fordev, only--mode,--port,--host,--localare accepted, mirroringcf-wranglerexactly. Parsed withnode:util.parseArgsstrict mode → unknown flags exit2. Do NOT add flags here unlesscf-wranglergrows them too. (There is no--configflag: the wrangler config is discovered bycloudflare()itself.) buildcf-vite buildruns Vite's full multi-environment app build viacreateBuilder().buildApp()(NOT the legacy single-environmentbuild()helper, which would skip the plugin's worker/build-output orchestration — mirrors Vite's ownvite buildCLI). It accepts only--mode(--port/--host/--localdon't apply to a build and exit2).- Build Output API forced for every verb.
main()setsCLOUDFLARE_VITE_FORCE_BUILD_OUTPUTunconditionally (before Vite loads the user's config), enablingexperimental.newConfig+experimental.newConfig.cfBuildOutput(overriding plugin config), which requires acloudflare.config.tsat the project root. The env var name and read logic live inbuild-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) andresolvePluginConfig. Both read directly fromprocess.env(NOT Vite'sloadEnv), sinceindex.tsruns before Vite resolves a root/mode and this is an internal bridge, not a.env-file knob. devcf-vite devboots Vite viacreateServer()against the user's ownvite.config.ts(which must includecloudflare()). 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).--localforces remote bindings off. There is no plugin env knob forremoteBindingsother thanCLOUDFLARE_VITE_FORCE_LOCAL, whichresolvePluginConfiginplugin-config.tshonours by overriding theremoteBindingsconfig option. Keep that override in sync if the flag semantics change.- Hotkeys differ by design.
cf-viteuses Vite's ownbindCLIShortcuts(h/r/q/…), not wrangler's hotkey set. The parent process should not assume identical hotkey UX across delegates. - Exit codes.
0graceful,2unknown verb / argv parse error,130SIGINT,143SIGTERM.
CONVENTIONS
- No named imports from
"wrangler"— must useimport * as wrangler from "wrangler"(namespace import only, enforced by eslint) - Top-level
awaitin entry — only possible because ESM-only - Playground directory
worker-♫/has unicode in name (intentional)
TESTING
- Unit tests:
.spec.tsin__tests__/ - E2E tests:
.test.tsine2e/, own vitest config - Playground tests: Playwright-based, tested across Vite 6/7/8 in CI