-
-
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
feat: build.modulePreload options #9938
Conversation
I think we should remove the |
if (typeof dep === 'object') { | ||
if (dep.runtime) { | ||
return dep.runtime | ||
} | ||
if (dep.relative) { | ||
return JSON.stringify(toRelative(dep.relative)) | ||
} | ||
throw new Error( | ||
`Invalid dependency object, no runtime or relative option specified` | ||
) | ||
} |
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 seems to be a very advanced feature, especially the runtime
part. I'm curious how Nuxt will be using this part of the API. Do they have their own runtime preload list?
IIUC this PR would also disable the optimization in #9491, or perhaps doesn't work only if resolveDependencies
is used. But I don't think it's a big issue since most won't be using this feature directly.
The rest looks great though.
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.
Nuxt is using runtime
to use its own function to resolve paths, like globalThis.__resolvePath(...)
.
I commented in #9491, that we should wait a bit to avoid breaking the ecosystem but I think we can still do the optimization after this PR.
The PR changed quite a bit after 9f1eaa5
(#9938)
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Tony Trinh <tony19@gmail.com>
Co-authored-by: Tony Trinh <tony19@gmail.com>
After 9f1eaa5 (#9938), @benmccann also interested in seeing if this PR is enough for SvelteKit module preload needs. The ssr manifest isn't modified by this PR, if you use that you have full control of the paths already. SvelteKit may need to replicate what we have done here for HTML, and for JS dynamic imports it should be now able to take advantage of |
The API spec looks great to me. (Though I've never created a meta-framework, so I don't have much confidence) About the name of |
Thanks for the review @sapphi-red. I would prefer to avoid the name advanced here, and in any case add an Advanced level in docs. This API in particular isn't as complex as |
Which version is this experimental feature targeted for release? Hopefully, it's asap... 😄 |
Hi It will even allow to solve a bug I saw today : in 3.1 the preloads are made with a HTTP header, and the header is several Kb long … that's more than the nginx default value of 1Kb, leading to our pre-production refusing to serve the page. EDIT : the bug has been created : sveltejs/kit#6790 |
@jpvincent we also discussed with @danielroe yesterday about being able to modify the injected CSS styles for a chunk. But these aren't module preloads, the CSS chunks are in the same list just because we are piping them through the same function but the result is an injected stylesheet that is awaited. I think we need a new API for these, independent of this PR. I think a new feature should be created so we gather enough use cases to justify it. |
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
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!
For those coming here after upgrading to Vite v4 and finding that suddenly their index.html file has a bunch of new {
// ...
build: {
modulePreload: {
resolveDependencies: () => [],
},
},
} Most importantly, This should be marked as a breaking change in the docs for migrating from v3 (https://vitejs.dev/guide/migration.html). |
Setting to false i get less bundle size
And i dont get double file fetching in FF |
I was able to make sure the preloads where removed from my index.html file with this. However, we do use React.lazy quite extensively through our application and see that, with Vite 4, on initialization the app still loads a lot of files that should be lazy loaded when the application hits a certain route. This worked fine earlier with Vite 3.2.2. |
@kleinfreund would you create a new issue with a minimal reproduction for the issue you are experiencing? Thanks! |
@patak-dev I’ve filed a bug report for As for the other matter I brought up in #9938 (comment), do you think it’s appropriate to say this should be documented as a breaking change? Do you also want me to file an issue for that? |
Thanks for creating the issue, I don't know yet. I think it is a regression rather than a breaking change. |
We are starting to gather feedback about |
Fixes #9680
Fixes #3133
Fixes #5991
Fixes #5120 (it was closed as won't implement)
Closes #7766
Description
See the issues above for examples of requests to be able to control module preload. We already discussed in a team meeting that we should implement support for completely disabling module preload and also to support filtering.
DONE: Pushing a WIP, so we can discuss the API, @danielroe @antfu maybe there is a chance to include this in 3.1 (or we can later add it to a patch). It is WIP, because we should keep the
.css
chunks... even when preload is disabled as the mechanism to preload .js chunks and add the needed styles is shared (in the PR currently I passed both throughmodulePreload.resolveDependencies
).Question: Should we only allow modifying the .js chunks? Or should we also pass the .css assets to
resolveDependencies
and expect the user to avoid filtering them?Edit: The new API will only receive an array of modules, CSS assets aren't included and are processed separatedly
docs
The polyfill can be disabled using
modulePreload: { polyfill: false }
. The previouspolyfillModulePreload
option has been deprecated.The list of chunks to preload for each dynamic import is computed by Vite. By default, an absolute path including the
base
will be used when loading these dependencies. If thebase
is relative (''
or'./'
),import.meta.url
is used at runtime to avoid absolute paths that depends on final the deployed base.Edited after 9f1eaa5 (#9938)
There is experimental support for fine grained control over the dependencies list and their paths using the
resolveDependencies
function. It expects a function of typeResolveModulePreloadDependenciesFn
The
resolveDependencies
function will be called for each dynamic import with a list of the chunks it depends on. A new dependencies array can be returned with these filtered or more dependencies injected, and their paths modified. Thedeps
paths are relative to thebuild.outDir
.The paths can be further modified by
experimental.renderBuiltUrl
. See new config file inpreload
test case and updated docs.What is the purpose of this pull request?