Support @cloudflare/vite-plugin for dev bindings access - #9
Merged
Conversation
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
force-pushed
the
JoviDeCroock/cf-vite-plugin
branch
from
April 7, 2026 22:14
82db83a to
a0e37e0
Compare
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>
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ViactAdapterinterface withpluginsandhandlesDevfields so adapters can inject Vite plugins and opt out of viact's Node-based dev SSR middlewarecloudflareAdapter()accepts a newvitePluginoption — passcloudflare()from@cloudflare/vite-pluginto run dev via workerd with full access to Cloudflare bindings (KV, D1, R2, Queues, etc.)create-viactscaffold now wires up the Cloudflare Vite plugin by default for new CF projects, includingsrc/worker.tsentry and updatedwrangler.jsoncTest plan
create-viactand verify bindings are accessible in dev🤖 Generated with Claude Code