Provide ability to extend vite-plugin-cloudflare#12743
Closed
aron-cf wants to merge 2 commits intocloudflare:mainfrom
Closed
Provide ability to extend vite-plugin-cloudflare#12743aron-cf wants to merge 2 commits intocloudflare:mainfrom
aron-cf wants to merge 2 commits intocloudflare:mainfrom
Conversation
|
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
Contributor
Author
|
Closed in favor of just supporting Sandbox SDK directly. This was implemented in #12794 |
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.
I've been tasked with figuring out how we integrate the cloudflare/sandbox-sdk with the Cloudflare
Vite plugin. Particularly the ability to run a Vite dev server within a sandbox while retaining
all the functionality of the host Vite dev server.
A sandbox can be exposed via a worker in development using a custom hostname in the form:
Routing requests to the sandbox touches a number of pieces.
vite-hmrprotocol.Theres a more comprehensive overview described in this internal document. But for now TLDR; it would be very useful to be able to extend the Cloudflare plugin (particularly access to miniflare) so that we can register our own middleware in the stack and handle Sandbox specific details.
This would let us iron out the user interface for working with Sandboxes without having to alter the implementation of the plugin significantly.
The proposal here is to provide the ability to register additional Vite plugins via an
experimental.additionalPluginsconfig option. These plugins get access to thePluginContextin the same way as the internal plugins.This would allow us to explore different implementations before proposing a final integration.
A plugin would look something like:
There is a full example of a vite-sandbox in this pull request cloudflare/sandbox-sdk#434.
Currently the entire
PluginContextis exposed, but it may be more prudent to expose a limited interface. I think primarily access to the resolved configs and miniflare are the most critical.I have added a basic test on top of the existing static one to verify it is wired up correctly. I'm happy to refactor that as needed.