-
-
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: add experimental option to skip SSR transform #11411
Conversation
aaf2f7b
to
e1fe017
Compare
A good loader implementation also requires access to 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.
Looks like a nice middle ground for now
When does something need to be externalized or not? IIUC this feature requires externalizing everything by default, which today works partially for non-linked packages. |
e1fe017
to
986c03b
Compare
I think most things are externalized for SSR by default. But you can opt out of externalization with
(I just pushed a version that exposes it, updating the OP). |
I published this under It doesn't cover many edge cases but it works. Breakpoints and sourcemaps work too. (Doesn't work on StackBlitz or CodeSandbox, not sure why yet) Update: A more complete example with the upcoming Update 2: Another one, this time with SvelteKit. |
Ah ok I misunderstood your point initially. I think it make sense to expose it perhaps as an experimental flag too. (EDIT: looks like you already did it 😄) |
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 quite like the idea of using loaders so putting my approval for now. But we may need a quick discussion before proceeding with this.
986c03b
to
1d8929e
Compare
I retracted the bit that exposes |
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.
We discussed this in the last meeting, and we decided to move forward with this as an experimental option to let the ecosystem play with this new SSR mode. Let's review later if we should move it out of experimental once we have enough use cases in the wild.
We are gathering feedback about this feature for future stabilization here: |
Description
This PR adds an experimental option to skip SSR transform so that we can use Vite directly in Node's (currently experimental) ESM loaders. You can think of it as a minimal alternative to #9740. This tiny change enables the ecosystem to experiment with this approach without modifying Vite's core.
Building a Node ESM loader on top of Vite using this approach would render #3288 and #3928 less urgent.
The PR also exposes(not necessary, import analysis plugin takes care of it, a simple "is first char dot or slash" check is enough)shouldExternalizeForSSR
which does most of the work in deciding whether a dep should be externalized. Exposing it makes it possible to use the same logic in loaders.Additional context
In SSR dev mode, Vite transforms ESM imports and exports into special forms like
__vite_ssr_import__
and__vite_ssr_exports__
. This PR adds an option to skip that transform so that transform output is valid native ESM. Of course it breaks normal operation but it allows using Vite in Node's ESM loaders.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).