js-inline-wasm
A tool for bundling a WebAssembly .wasm file into a .js ES6 library file with async loading.
Installation
npm install -D js-inline-wasm
Usage
$ inlinewasm sample.wasm [--output sample.js] [--type fetch]
In package.json
scripts:
Options
-
--input file The .wasm file to inline
-
-o, --output file The .js file to create
-
-t, --type typeName The type of JavaScript file to generate
-
-h, --help Show this Help page
Types
Each type outputs a different variant of JavaScript file
-type fetch
Creates a JavaScript file with a default export function that can be used anywhere you could use fetch()
. e.g.
; // sample.js contains the bundled .wasm WebAssembly ;
-type decoded
Creates a JavaScript file with a default export byte array containing the decoded .wasm content
Note: You'll probably want to use WebAssembly.instantiateStreaming()
in most cases, as it is more efficient than instantiate()
.
; // sample.js contains the bundled .wasm WebAssembly ;
-type encoded
Creates a JavaScript file with a default export string value containing the base64 encoded .wasm file
; // sample.js contains the bundled .wasm // Decode the base64 string then compile...