wasm-inliner

raw JSON →
1.0.0 verified Mon Apr 27 auth: no javascript

Zero-config WASM to inline JS bundler. Version 1.0.0 converts a .wasm file into a standalone JavaScript file embedding the binary as Base64, eliminating the need for fetch, CORS headers, or separate hosting. Suitable for both browser and Node.js environments, it provides a simple init function to instantiate the module. Released as a CLI tool and library, it targets small WASM modules and prioritizes simplicity over complex build integration. Differentiates from full build systems like webpack/wasm-pack by being a single-purpose, no-config utility.

error SyntaxError: Cannot use import statement outside a module
cause The generated bundle uses ESM syntax but is loaded in a non-module script or CommonJS context.
fix
Add type="module" to your script tag, or use dynamic import() in Node.
error Error: WebAssembly.instantiate(): expected magic word 00 61 73 6d
cause The .wasm file is corrupted or not a valid WebAssembly binary.
fix
Verify the .wasm file is correct and re-run the inliner on it.
gotcha Generated bundle wraps WASM as Base64; large files increase JS size significantly.
fix Only use for small WASM modules (<1MB). For larger files, prefer streaming compilation.
gotcha The generated bundle initializes WASM synchronously within the async init function, which may block the main thread if the WASM is large.
fix Ensure initWasm() is called early and consider using Web Workers for heavy modules.
gotcha This tool does not handle WASM imports (e.g., environment, memory) beyond basic WASI stub. Complex WASM modules may fail.
fix Pre-process your WASM to use simple exports/imports, or use a more comprehensive bundler like wasm-pack.
npm install wasm-inliner
yarn add wasm-inliner
pnpm add wasm-inliner

Shows how to import the generated bundle and initialize the WASM module with a simple demo function call.

const initWasm = (await import('./your-file.bundle.js')).default;
const instance = await initWasm();
console.log(instance.add(5, 10));