-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
fix(optimizer): support new Worker
and new URL(..., import.meta.url)
for pre-bundled dependencies
#17837
Open
hi-ogawa
wants to merge
27
commits into
vitejs:main
Choose a base branch
from
hi-ogawa:feat-pre-bundle-new-url
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains 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
Run & review this pull request in StackBlitz Codeflow. |
hi-ogawa
commented
Aug 9, 2024
const subUrl = new URL('./sub.js', import.meta.url) | ||
|
||
export default () => import(subUrl) | ||
export default () => import(/* @vite-ignore */ String('./sub.js')) |
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.
This case is now compatible, so I made it more "incompatible" for the tests added in #16080
Closed
7 tasks
hi-ogawa
changed the title
feat(optimizer): support
fix(optimizer): support Aug 27, 2024
new Worker
and new URL(..., import.meta.url)
for pre-bundled dependenciesnew Worker
and new URL(..., import.meta.url)
for pre-bundled dependencies
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.
Description
related #16418, #8427, #11672
I'm exploring
new URL
andnew Worker
support for pre-bundled dependencies as a user land vite plugin (and mostly as a standalone esbuild plugin) in https://github.com/hi-ogawa/vite-plugins/tree/main/packages/pre-bundle-new-url. From what I tested on various examples, this seems to cover well known scenarios, so I'm starting with this draft PR to discuss whether this could be moved to core.The approach is based on 3rd one suggested in #16418 (comment). This intercept
onLoad
hooks for all js files, so performance impact is one concern (there are other concerns too and I wrote them as TODO in the code).Some examples I tested are:
optimizeDeps.exclude
for devthree-gpu-pathtracer
is currently broken for vite build due to Build fails on self reference workernew Worker(new URL(..., import.meta.url))
in dependency #17843I think the main question to ask first is whether we need to rash into supporting this on top of current esbuild. Maybe would it be better to suggest and test user land workaround (either simply
optimizeDeps.exclude
, which users already see as a warning message, or my plugin) and wait for a bundler level support by esbuild or rolldown?Also regardless of whether waiting for esbuild or rolldown, it's probably important to guide their implementation so that it'll be directly usable for Vite. I made a bundler comparison table in https://github.com/hi-ogawa/reproductions/tree/main/webpack-new-url-worker-bundle-or-copy and it seems esbuild's future implementation (though it could be stale PR) might not match well with what Vite needs. If anyone has suggestions for what we can do right now, I'm curious to hear.