Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for Node's experimental ESM loader API so that you can do
node --loader vite/loader server.js
to start a dev server and load server code without needingssrLoadModule
and the like. It providesresolve
andload
hooks that transpile files with Vite's SSR transform, slightly modified to fit the use case.Source maps seem to be fully working so the PR also provides a workaround for #3288 and makes #3928 less urgent.
In it's current form, it is able to run Rakkas Realworld (with slight modifications to Rakkas and the demo itself), which is a medium-sized but fairly complex project (with virtual modules,
external
s,noExternal
s, CJS and ESM deps, and the like). But there may be a lot more edge cases to be addressed and decisions to be made. I opened the PR early to start the discussion.Alternatively, the loader could live in its own package but then we need to expose a bit more functionality. Currently the most pervasive change is adding a third value (
"loader"
) foroptions.ssr
that is passed totransform
hooks. Alternative approaches are possible.There is an
ssr-react-loader
playground that demonstrates the usage. Tests don't pass yet (because they're copied verbatim fromssr-react
) but I can adapt them if this gets green lighted.Additional context
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).