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

fix(ssr): support externalized builtins for webworker #15656

Merged
merged 1 commit into from
Jan 19, 2024

Conversation

bluwy
Copy link
Member

@bluwy bluwy commented Jan 19, 2024

Description

webworker builds such as Cloudflare these days support ESM and nodejs compat modules. So some framework may choose to noExternal: true but externalize the nodejs builtins so that they can be used in the runtime.

Currently our hardcoded "if ssrNoExternal === true => error" flow, blocks bundling when encountering imports to the builtin. To be consistent with the new description in Vite 5.1:

https://main.vitejs.dev/config/ssr-options.html#ssr-noexternal

ssr.noExternal ... However, dependencies explicitly listed in ssr.external (using string[] type) can take priority and still be externalized.

If the builtins are specified in ssr.external, we will now allow bundling it.

Additional context

I thought about re-using shouldExternalize to update the conditions, but it has its internal isBuiltin check that doesn't make it work.

This PR could also unblock frameworks to do a single Vite build, instead of needing a secondary esbuild bundle for cloudflare worker builds.


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, especially the Pull Request Guidelines.
  • 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).
  • Update the corresponding documentation if needed.
  • Ideally, include relevant tests that fail without this PR but pass with it.

@bluwy bluwy added p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority) feat: ssr labels Jan 19, 2024
Copy link

stackblitz bot commented Jan 19, 2024

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@patak-dev patak-dev merged commit 639bbd6 into main Jan 19, 2024
11 checks passed
@patak-dev patak-dev deleted the ssr-webworker-external branch January 19, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p3-downstream-blocker Blocking the downstream ecosystem to work properly (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants