Wasm
Rsbuild provides native support for WebAssembly (WASM) modules, allowing you to import and use .wasm files directly in your project.
WebAssembly (Wasm) is a portable, high-performance binary format designed to execute CPU-intensive computing tasks in modern web browsers, bringing near-native performance and reliability to the web platform.
Import
You can reference a WebAssembly module in a JavaScript file using named imports:
WebAssembly modules can also be imported via dynamic import:
You can also get the path of a WebAssembly module using the new URL syntax:
Output directory
When you import a .wasm asset, Rsbuild outputs it to the dist/static/wasm directory by default.
You can change the output directory for .wasm files using the output.distPath configuration:
Type declaration
When you import a WebAssembly file in TypeScript code, you usually need to add the corresponding type declaration.
For example, if the add.wasm file exports an add() method, you can create an add.wasm.d.ts file in the same directory and add the corresponding type declaration:

