-
-
Notifications
You must be signed in to change notification settings - Fork 757
feat: implement UniversalCompileAsyncWasmPlugin for universal chunk loading #12471
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
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements the UniversalCompileAsyncWasmPlugin to enable WebAssembly module loading that works in both browser and Node.js environments. The plugin automatically detects the runtime environment using feature detection (typeof document !== 'undefined' || typeof self !== 'undefined') and uses the appropriate loading mechanism: the fetch API for browsers and fs.readFile for Node.js. This follows webpack's universal loading pattern and integrates with rspack's existing wasm loading infrastructure.
Key changes include:
- Addition of the
WasmLoadingType::Universalvariant and associated plugin implementation - Extension of entry options and output configuration to support per-entry
wasmLoadingsettings - Updates to default configuration logic to automatically enable universal loading when appropriate (output.module && environment.dynamicImport && mixed runtime capabilities)
- Test suite updates enabling universal wasm tests and converting sync wasm tests to async
Reviewed changes
Copilot reviewed 37 out of 39 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
crates/rspack_plugin_wasm/src/loading_plugin.rs |
Implements UniversalCompileAsyncWasmPlugin with environment detection and dual-path loading logic |
crates/rspack_plugin_wasm/src/runtime.rs |
Extends AsyncWasmLoadingRuntimeModule to support additional code injection points for universal loading |
crates/rspack_plugin_wasm/src/lib.rs |
Exports the new UniversalCompileAsyncWasmPlugin |
crates/rspack_core/src/options/output.rs |
Adds Universal variant to WasmLoadingType enum and updates error messages |
crates/rspack_core/src/options/entry.rs |
Adds wasm_loading field to EntryDescription for per-entry configuration |
crates/rspack_core/src/chunk_group.rs |
Adds wasm_loading to EntryOptions struct and merge logic |
crates/rspack/src/builder/mod.rs |
Implements logic to enable universal wasm loading when chunk loading is universal |
crates/rspack_binding_api/src/options/entry.rs |
Adds wasm_loading to JavaScript binding interface |
crates/node_binding/napi-binding.d.ts |
Updates TypeScript definitions to include wasmLoading in entry options |
packages/rspack/src/config/defaults.ts |
Updates default wasmLoading to return "universal" when appropriate based on target platform |
packages/rspack/src/config/normalization.ts |
Adds wasmLoading to EntryDescriptionNormalized type |
packages/rspack/src/builtin-plugin/EntryPlugin.ts |
Includes wasmLoading in getRawEntryOptions return value |
packages/rspack/etc/core.api.md |
Updates API documentation with wasmLoading in EntryDescriptionNormalized |
crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs |
Adds wasm_loading to worker entry options |
tests/rspack-test/configCases/wasm/universal/* |
Enables universal wasm loading test |
tests/rspack-test/configCases/wasm/*/test.filter.js |
Removes TODOs for now-supported features (sync wasm, AsyncWebAssemblyModulesPlugin hooks) |
tests/rspack-test/configCases/wasm/*/rspack.config.js |
Converts sync wasm tests to async and removes commented-out sync configurations |
tests/rspack-test/configCases/wasm/wasm-in-initial-chunk-error/* |
Removes entire sync wasm test case |
tests/rspack-test/configCases/url/dynamic-template-literals-expr/test.filter.js |
Enables test for webpackComments in new URL with new Worker |
Comments suppressed due to low confidence (1)
crates/rspack/src/builder/mod.rs:3086
- The commented-out code for collecting wasm_loading from entry descriptors should likely be uncommented and implemented now that wasmLoading support is added to EntryOptions. This would allow entries to specify their own wasm loading type, similar to how chunk_loading works.
// for (_, desc) in entry.iter() {
// if let Some(wasm_loading) = &desc.wasm_loading {
// enabled_wasm_loading_types.push(wasm_loading.clone());
// }
// }
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Rsdoctor Bundle Diff AnalysisFound 5 project(s) in monorepo. 📁 react-10kPath:
📦 Download Diff Report: react-10k Bundle Diff 📁 react-1kPath:
📦 Download Diff Report: react-1k Bundle Diff 📁 react-5kPath:
📦 Download Diff Report: react-5k Bundle Diff 📁 romePath:
📦 Download Diff Report: rome Bundle Diff 📁 ui-componentsPath:
📦 Download Diff Report: ui-components Bundle Diff Generated by Rsdoctor GitHub Action |
📦 Binary Size-limit
❌ Size increased by 11.00KB from 48.28MB to 48.29MB (⬆️0.02%) |
CodSpeed Performance ReportMerging #12471 will not alter performanceComparing Summary
|
chenjiahan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we update the documentation to reflect this change?
Summary
This PR implements the
UniversalCompileAsyncWasmPluginfor universal chunk loading, which allows WebAssembly modules to be loaded in both browser and Node.js environments. The plugin automatically detects the runtime environment and uses the appropriate loading mechanism (fetch API for browsers, fs.readFile for Node.js).The implementation follows the webpack's UniversalCompileAsyncWasmPlugin pattern and adds support for the
universalwasm loading type. WhenwasmLoading: "universal"is configured, the plugin generates code that can work in both environments by detecting the presence ofdocumentorselfglobals.By the way, modified some test cases from old
webassembly/synctowebassembly/async, rspack has no plan to supportwebassembly/sync.Checklist