feat(wasm)!: support wasm modules in ESM output with compile and preserve modes - #1726
Conversation
Deploying rslib with
|
| Latest commit: |
676c3bd
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://817992b1.rslib.pages.dev |
| Branch Preview URL: | https://feat-wasm-phase-1.rslib.pages.dev |
|
The |
a47243f to
7c9f9c7
Compare
|
Temporarily marked as draft cuz I observe some outputs related to source phase imports are incorrect. I’m trying to fix these issues in Rspack: web-infra-dev/rspack#14673 & web-infra-dev/rspack#14674 |
312fb2a to
6fa95ff
Compare
7c36c3d to
d002906
Compare
d002906 to
0a7b5fb
Compare
70f157b to
5ccbcef
Compare
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: de0e3cb7db
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7abee17845
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
# Conflicts: # packages/core/src/config.ts
|
<agent: daily-job rspack eco-ci> Daily AI eco-ci triage found that this PR introduced the current Evidence:
The mechanical cause is a runtime-version mismatch: this PR added source-phase WebAssembly output tests that require Node 24 syntax support, while the eco-ci Rspack build action currently pins Node 22.22.3. The preferred fix is to run this suite on Node 24; a downstream fallback is to gate the two runtime-import assertions on Node 24 while retaining build-output assertions on Node 22. |
Summary
Add a
wasmlibrary option to control how.wasmmodules are handled in ESM output.wasm.mode:'compile'— Rspack parses the.wasmmodule and generates the JS glue and runtime to load it.'preserve'— keep.wasmas a real ESM import and emit the binary with its source-relative path and original filename. This mode is only available whenbundleisfalse.When
modeis unset, it defaults to'compile'forbundle: trueand'preserve'forbundle: false. The option is only effective forformat: 'esm'.Includes integration tests covering compile/preserve × bundle/bundleless, and a new WebAssembly guide (EN + ZH) documenting the modes, supported import forms (static, dynamic,
import source,import.source()), andwasm-bindgenusage.Breaking changes
For ESM libraries using
bundle: false,.wasmfiles are no longer emitted as standalone bundleless entries that generate JavaScript wrappers. They now default towasm.mode: 'preserve', so output JavaScript retains.wasmimports and binaries keep their source-relative paths and original filenames.To retain the compile behavior, set
wasm.modeto'compile'. No migration is required forbundle: true, which usescompilemode by default.Checklist