A Webpack loader that allows importing .wasm binary files directly into JavaScript bundles as constructor functions returning a Promise resolving to WebAssembly.Instance. Current stable version 1.3.0. It eliminates the need for manual fetch and instantiation, converting wasm bytes to Uint8Arrays embedded in the JS bundle. Differentiators include optional dead code elimination via `dce=1` query parameter and support for passing custom import objects. Requires Webpack and Node.js, with peer dependency on wasm-dce. Suitable for basic wasm modules; for complex Emscripten output, custom imports are necessary.
npm install wasm-loaderVerified import paths — ran on the pinned version, not inferred.
Shows how to configure Webpack with wasm-loader and use the default export to instantiate a WebAssembly module and call an exported function.
Use '.then()' to access instance or await the promise.
Pass custom import object to the loader function matching module expectations.
Test thoroughly and consider alternatives if DCE fails.
Consider separate loading strategies (e.g., dynamic import) for large wasm.
Add { test: /\.wasm$/, use: 'wasm-loader' } to module.rules in webpack.config.js.Ensure webpack config applies wasm-loader to .wasm files and use correct import statement: import createInstance from './file.wasm'.
Ensure importsObject argument is a plain object with appropriate properties (e.g., { env: { memory: ..., table: ... } }).