-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
Configure transitive dependencies in ssr
external
/noExternal
#9919
Comments
What we have right now (both in Vite 2 and Vite 3) is:
Dependencies of the project are external by default, so if we have:
And dep_A is configured as noExternal, dep_B will still be external because it is a dep of the project. But if we have
Then both dep_A and dep_B will be noExternal. So if the user wants both dep_A and dep_B in the first case to be noExternal, both will need to be added to If I recall correctly, at one point Vite did differentiate between |
Yeah, I sent the PR to switch it about a year ago: #4699. It looks like part of the issue back then was that we were always using Your comment suggested that |
@benmccann I think this PR, that is trying to go in the opposite way of what you want here, is a good place to see how this works: Here is the code that is trying to resolve the dep from root, and filters subdependencies as noExternal:
cc @bluwy, in Vite 4, shouldn't we evaluate having |
In the case I'm looking at
Calls function returned by
Calls function returned by
Calls
I might be missing it, but I don't see anywhere in here where |
I think the idea so far is to not give special treatment to
Yeah |
I think it would still be possible given the example you shared. If the user explicitly externalizes Another thing I'll mention is that if we have Handling things transitively would also add some simplifications. E.g. we wouldn't need the |
Description
SvelteKit needs to add Svelte libraries to
noExternal
to compile the.svelte
files. We'd also likedevDependencies
to be bundled anddependencies
not to be. This is because when people runnpm install
in production they're not getting theirdevDependencies
installed, so it'd be nice to bundle those.This is almost impossible because we can't just add the
devDependencies
tonoExternal
since it doesn't also add the transitive dependencies.We can't set
noExternal
totrue
and add thedependencies
toexternal
becauseexternal
takes precedence making it easy for a user to add a Svelte library todependencies
/external
which would cause it to break since Svelte needs to be bundled (proposed in sveltejs/kit#6301). If you do the reverse and adddevDependencies
tonoExternal
it still allowsvite-plugin-svelte
to add things tonoExternal
without harsh overridesIt also turns out that
noExternal: true
is basically impossible to use because it validates that you don't import any Node built-ins, which is maybe useful for deploying to a target like Cloudflare workers, but quite often is a frustrating restriction. (Edit: turns out you can work around that sveltejs/kit#6301 (comment))Suggested solution
The
ssr.external
andssr.noExternal
docs are fairly vague. If my recollection serves me, one deals with libraries and one with.js
files. It would be nice to clarify what they operate onGiven my current lack of clarity as to how these options work, it's hard for me to suggest solutions. Is it possible for the options to take effect not just for the individual libraries, but also their dependencies?
Alternative
This is currently being worked around by bundling the Vite output with esbuild, but that seems like it should be unnecessary. The second bundling step adds an additional layer of complexity and causes users to hit all of esbuild's bugs (e.g. sveltejs/kit#6440)
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: