-
-
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
Omit __vitePreload
if dependency array is empty
#13952
Comments
➕ 💯 for this. Incredibly frustrating to set |
any updates regarding this issue? It's frustrating to have this polyfill in web extensions. |
Vite currently can't omit the While Vite could maybe walk back and remove the If the idea is to have no preloading at all then So altogether, I'm not sure if there's anything else we can do here. |
Currently to use vite on WebExtension, the public dir can be useful. |
Yes, the overhead of the empty array is negligible. The key issue though as mentioned in the original post is that there are some environments where specific files 1) need dynamic imports 2) cannot be modules. (e.g. browser extension content-scripts). I can hack around to remove the
PS: In writing this it occurred to me that I might be able remove the |
I don't quite understand this. Dynamic imports only work for modules, if it can't be modules, it's conflicting the idea.
You can have a transform hook like this: {
transform: {
order: 'post'
handler() {}
}
} The
I think this depends on Vite's target audience focus, which is mainly browser apps, SSR, backend integrations, etc. Developing web extensions isn't part of the original goal so requiring workarounds seems fair to me. |
i want know the work around please i am using astro BTW |
The answer is right in the comment you highlighted. Write a Vite plugin that finds the Bluwy also gives you the hint that you can work around Vite's plugin ordering by passing an object handler with {
transform: {
order: 'post'
handler(code, id) {
// Check if `id` is my special file that shouldn't have ` __vitePreload`.
// If Vite has already added the preload by the time we're here to remove it
}
}
} PS: If need to preserve source maps you can use |
Preloading seems to automatically change my js loading order, I need to disable this behavior. If anyone looks at this question, I will provide examples and scenarios |
I found a workaround to prevent
with:
Although modifying the codebase isn’t ideal, this approach bypasses |
Description
Vite provides
modulePreload.resolveDependencies
to give fine-grained control over module preloading. However, when I exclude module dependencies, it still imports the preloader. This is a feature request not to render the preloader at all if the dependency list is empty.This has the additional benefit that if no preloading happens, I don't have to pay the price for the preloading script.
I need this for a Vite plugin generating content scripts for browser extensions. Content scripts are non-modules and thus don't allow the
import func from 'file'
syntax. Additionally, since files are local, the waterfall without preloading is negligible.Suggested solution
Given:
Instead of:
output:
Alternative
I considered creating a plugin, but Vite runs built-in
"enforce": "post"
plugins last after user"post"
plugins...so I can't override the import within thetransform
hook.Additional context
This is essentially a follow up of #5991 and #9938. This is a common pattern (#8023 (comment)) in browser extensions.
Validations
The text was updated successfully, but these errors were encountered: