Skip to content

feat(wasm)!: support wasm modules in ESM output with compile and preserve modes#1726

Open
elecmonkey wants to merge 18 commits into
mainfrom
feat/wasm-phase-1
Open

feat(wasm)!: support wasm modules in ESM output with compile and preserve modes#1726
elecmonkey wants to merge 18 commits into
mainfrom
feat/wasm-phase-1

Conversation

@elecmonkey

Copy link
Copy Markdown
Member

Summary

Add a wasm library option to control how .wasm modules are handled in ESM output.

wasm.mode:

  • 'compile' — Rspack parses the .wasm module and generates the JS glue and runtime to load it.
  • 'preserve' — keep .wasm as a real ESM import and emit the binary. In bundle mode the binary is emitted as a content-hashed asset; in bundleless mode it keeps the source-relative path and original filename.

When mode is unset, it defaults to 'compile' for bundle: true and 'preserve' for bundle: false. The option is only effective for format: '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()), and wasm-bindgen usage.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings June 28, 2026 16:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 28, 2026

Copy link
Copy Markdown

Deploying rslib with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2e3625e
Status: ✅  Deploy successful!
Preview URL: https://a9223171.rslib.pages.dev
Branch Preview URL: https://feat-wasm-phase-1.rslib.pages.dev

View logs

@elecmonkey
elecmonkey marked this pull request as draft June 29, 2026 02:50
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rslib-v0 with  Cloudflare Pages  Cloudflare Pages

Latest commit: e3e100b
Status:⚡️  Build in progress...

View logs

@elecmonkey

Copy link
Copy Markdown
Member Author

The dynamic source phase: preserve tests require a fix in Rspack's RslibPlugin to preserve import.source() in dynamic external rendering: web-infra-dev/rspack#14615

@elecmonkey
elecmonkey force-pushed the feat/wasm-phase-1 branch from a47243f to 7c9f9c7 Compare July 1, 2026 17:54
@elecmonkey
elecmonkey marked this pull request as ready for review July 1, 2026 18:01
@elecmonkey elecmonkey changed the title feat(wasm): support wasm modules in ESM output with compile and preserve modes feat(wasm)!: support wasm modules in ESM output with compile and preserve modes Jul 3, 2026
@elecmonkey
elecmonkey marked this pull request as draft July 3, 2026 11:44
@elecmonkey

Copy link
Copy Markdown
Member Author

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

@elecmonkey
elecmonkey marked this pull request as ready for review July 7, 2026 17:06
@elecmonkey
elecmonkey force-pushed the feat/wasm-phase-1 branch from 312fb2a to 6fa95ff Compare July 8, 2026 06:24
@elecmonkey
elecmonkey marked this pull request as draft July 8, 2026 06:27
@elecmonkey
elecmonkey marked this pull request as ready for review July 8, 2026 07:48
@Timeless0911

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/core/src/wasm/path_utils.ts Outdated
@elecmonkey

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3981846376

ℹ️ 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".

Comment thread packages/core/src/wasm/preserve.ts
@elecmonkey

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40c2fbbddc

ℹ️ 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".

Comment thread packages/core/src/wasm/path_utils.ts Outdated
Comment thread packages/core/src/config.ts
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.

3 participants