Skip to content

Support @cloudflare/vite-plugin for dev bindings access - #9

Merged
JoviDeCroock merged 10 commits into
mainfrom
JoviDeCroock/cf-vite-plugin
Apr 7, 2026
Merged

Support @cloudflare/vite-plugin for dev bindings access#9
JoviDeCroock merged 10 commits into
mainfrom
JoviDeCroock/cf-vite-plugin

Conversation

@JoviDeCroock

Copy link
Copy Markdown
Owner

Summary

  • Extend ViactAdapter interface with plugins and handlesDev fields so adapters can inject Vite plugins and opt out of viact's Node-based dev SSR middleware
  • cloudflareAdapter() accepts a new vitePlugin option — pass cloudflare() from @cloudflare/vite-plugin to run dev via workerd with full access to Cloudflare bindings (KV, D1, R2, Queues, etc.)
  • create-viact scaffold now wires up the Cloudflare Vite plugin by default for new CF projects, including src/worker.ts entry and updated wrangler.jsonc
  • Added virtual module type declarations and updated adapter docs with usage examples

Test plan

  • All 16 unit tests pass (including updated scaffold assertions for CF vite plugin, worker entry, and wrangler config)
  • Build and typecheck pass
  • Manual: scaffold a new CF project with create-viact and verify bindings are accessible in dev

🤖 Generated with Claude Code

JoviDeCroock and others added 3 commits April 8, 2026 00:14
Extend ViactAdapter with `plugins` and `handlesDev` fields so adapters
can inject Vite plugins and control dev SSR. The Cloudflare adapter
accepts a `vitePlugin` option to run dev via workerd, giving API routes
and loaders access to KV, D1, R2, etc. The create-viact scaffold now
wires this up by default for new Cloudflare projects.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The cloudflare adapter now always includes the vite plugin internally
instead of requiring it as a user-facing option. Also bumps wrangler
peer dep to ^4.81.0 to satisfy @cloudflare/vite-plugin.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The CF vite plugin overrides the entry to src/worker.ts during dev via
its config option, while wrangler.jsonc keeps main pointed at the
pre-built dist/server/server.js so wrangler deploy works without Vite.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoviDeCroock
JoviDeCroock force-pushed the JoviDeCroock/cf-vite-plugin branch from 82db83a to a0e37e0 Compare April 7, 2026 22:14
JoviDeCroock and others added 7 commits April 8, 2026 00:16
The adapter now points the CF vite plugin's entry at virtual:viact/server
directly, so users don't need a boilerplate src/worker.ts file.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…pter

The viact plugin now handles @cloudflare/vite-plugin internally when the
adapter ID is "cloudflare", keeping ViactAdapter minimal. No user-facing
files or config needed — just cloudflareAdapter() and it works.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a Register interface that users augment to set their context type
once — all route args types pick it up automatically. For Cloudflare
projects, a generated src/env.d.ts wires up env and executionContext.

The CF vite plugin is now lazy-loaded via dynamic import() in an async
config hook to avoid pulling wrangler types into non-CF projects.
Moved @cloudflare/vite-plugin to optional peer dep.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add a Register interface that users augment to set their context type
once — all route args types pick it up automatically. For Cloudflare
projects, a generated src/env.d.ts wires up env and executionContext.

The CF vite plugin is lazy-loaded via dynamic import() to avoid pulling
wrangler types into non-CF projects. Also fix dev mode clientEntryUrl
fallback so scripts/styles are present when running via workerd.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ypes

Internal framework types (modules, registry, runtime plumbing) use
`any` for context so the generic TContext in handleViactRequest remains
compatible. Only BaseRouteArgs, LoaderArgs, MiddlewareArgs, and
ApiRouteHandler default to RegisteredContext for user code.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JoviDeCroock
JoviDeCroock merged commit e54edcb into main Apr 7, 2026
1 check passed
@JoviDeCroock
JoviDeCroock deleted the JoviDeCroock/cf-vite-plugin branch April 7, 2026 22:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant