close
  • English
  • lib.wasm

    • Type:
    type Wasm = {
      mode?: 'compile' | 'preserve';
    };
    • Default: undefined

    Configure how Rslib handles .wasm modules used with the WebAssembly ESM Integration proposal syntax.

    See WebAssembly for more details.

    wasm.mode

    • Type: 'compile' | 'preserve'
    • Default: 'compile' when bundle is true, 'preserve' when bundle is false

    Controls how .wasm modules are emitted.

    • 'compile': Rspack parses the .wasm module and generates JavaScript glue code and runtime loading logic. Suitable when the library is consumed directly by a runtime such as Node.js or the browser.
    • 'preserve': Rslib keeps the .wasm import in the output JavaScript and emits the binary as-is. This mode requires bundle to be false and is suitable when the library is consumed by another build tool or a runtime that supports WebAssembly ESM Integration natively.

    In preserve mode, the .wasm file keeps its source-relative path and original filename. output.distPath.wasm and output.filenameHash do not affect .wasm files in preserve mode.

    Rslib updates JavaScript imports so they continue to point to the emitted .wasm files. It does not rewrite imports stored inside a WebAssembly binary. If a .wasm file imports JavaScript, keep the relative output path and filename of that JavaScript file unchanged.

    rslib.config.ts
    export default {
      lib: [
        {
          bundle: false,
          format: 'esm',
          wasm: {
            mode: 'preserve',
          },
        },
      ],
    };
    Note

    wasm can only be configured when format is 'esm' (the default value). In addition, wasm.mode: 'preserve' requires bundle to be false. The build will fail for unsupported combinations.