-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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(optimizer): nested optimization #4634
Conversation
Tests fixed. Turns out when linking a cjs package via |
Should we add some documentation to https://vitejs.dev/guide/dep-pre-bundling.html and https://vitejs.dev/config/#dep-optimization-options so that users know this new option exists? |
@benmccann Yeah I'll update the config docs regarding this feature, looks like there's a cjs warning note for I'm not sure this is something we'll want to introduce in the guide though, it's solving a specific edge case, and it feels odd to add a paragraph about this. |
Cool. Nice update on the docs! The other thing I wonder about is if we should come up with a better separator than Thanks again for this! Really excited about it |
I'm happy to change |
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.
@bluwy we discussed this with the team today and this is feat is approved. Thanks for pushing for this. There may be a better way to deal with these dependencies in the future (like enabling transpilation of .vue/.svelte/etc files in node_modules) but for the moment this seems like a good tool to enable SvelteKit and others to work around the current issues.
About the separator, your proposal of using the CSS selector sounds better than something that looks like a path. So instead of /node_modules/, something like include: ['foo > bar']
should be familiar enough to users.
Thanks @patak-js. Excited to get this in! I've updated to use the |
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 think we should merge this, and we can keep working to improve on it as people start using it. We could wait until Tuesday though to see if someone else from the reported bugs could try it out and merge it before 2.5.2
About 4, it may be interesting to explore although it is a breaking change. So we may need to add something like
export default defineConfig({
optimizeDeps: {
exclude: ['#esm-dep'] // only main dep, don't exclude subdependencies
}
})
It is a bit strange to me that opting out of optimization would still optimize subdeps by default (maybe [ 'esm-dep!' ]
, hard to find a relatable notation).
I'm running a monorepo where I want to exclude dependencies which are packages in the monorepo from prebundling, but include dependencies of those packages. If I'm understanding this correctly then this feature should be perfect for this use case, right? I've written a script which recursively produces a list of those dependencies in the format described here I can work around the issue by hoisting ( Am I:
Sorry to hijack an old PR thread, but it seems like the most relevant place to discuss this. |
By default, linked packages in monorepos are excluded by default, and are also scanned for dependencies for inclusion, so you don't have to do those manually. This PR provides a way to re-include nested deps by an excluded dep, e.g. You shouldn't need shamefully hoist, but judging from your comment about "new dependencies found", it may likely be an issue where Vite doesn't scan fully by default due to the code structure, but it does scan into your linked package. Perhaps https://github.com/antfu/vite-plugin-optimize-persist would help, but I don't quite know why that happens. You can bring this to a discussion and ping me if you like. |
Description
Support adding
some-lib > nested-lib
tooptimizeDeps.include
. Allowingnested-lib
to be optimized if we excludesome-lib
from optimization. For example:Additional context
some-lib > nested-lib
allows any amount of space around the>
.p4 important
). Further work continued in Automatically add svelte libraries to vite.optimizeDeps.exclude sveltejs/vite-plugin-svelte#125.p4 important
), allowing a workaround.optimizeDeps.exclude: ['some-lib/*']
to explicitly exclude the entire tree? Currently, just specifyingsome-lib
will exclude the entire tree.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).