-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Support ctx.exports in the Vite plugin
#11238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 37146eb The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
69919d4 to
d4e9916
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
59a54d3 to
ec6fc66
Compare
|
Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
ctx.exportsctx.exports in the Vite plugin
5af2908 to
c44ccc4
Compare
c44ccc4 to
097065b
Compare
|
Could you update the description to give some background for the change – why it's needed, how it's used etc? |
Updated. |
edmundhung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still going through the second half of the commits. Just a few nits so far
edmundhung
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Just a few minor nits.
packages/vite-plugin-cloudflare/playground/ctx-exports/__tests__/ctx-exports.spec.ts
Outdated
Show resolved
Hide resolved
… move warnings playground into e2e test. This is because the dev server will now error on startup.
097065b to
37146eb
Compare
Fixes #000.
ctx.exportsis now supported in the runtime (see https://developers.cloudflare.com/workers/runtime-apis/context/#exports). Invite dev, the user's Worker entry module is not the top-level module that workerd sees. Instead the top-level module exports proxy classes that interface with Vite to fetch the user's code. Because of this,ctx.exportswould not automatically work as the exports to include in this module can not be determined from the user's config. We now run the code in the user's Worker entry module when starting the dev server to determine the exports that should be included.Summary
Initial server start
Note that restarting the Vite dev server itself is not possible during the initial start as the server has not yet been fully initialised. Restarting Miniflare is therefore the better option during this phase and is more optimal.
Updates to Worker entry modules
Note that restarting Miniflare without also restarting the dev server is problematic at this stage. This is because the dev server restart includes teardown and reinitialisation of environments that would otherwise have to be replicated somehow. Restarting the dev server is the best option in this phase and makes the behaviour of updating export types equivalent to updating the Worker config file.