Skip to content
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

WIP: feat: Node ESM loader #9740

Closed
wants to merge 1 commit into from
Closed

Conversation

cyco130
Copy link
Contributor

@cyco130 cyco130 commented Aug 18, 2022

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 needing ssrLoadModule and the like. It provides resolve and load 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, externals, noExternals, 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") for options.ssr that is passed to transform 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 from ssr-react) but I can adapt them if this gets green lighted.

Additional context


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@patak-dev
Copy link
Member

Closing after discussing with @cyco130. If you are interested in this approach, Fatih implemented it outside of core. Check out:

@cyco130 may propose upstreaming this approach again in the future.

@patak-dev patak-dev closed this Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants