🍣 A Rollup which allows importing and bundling WebAssembly modules.
WebAssembly Modules are imported asynchronous as base64 strings. Small modules can be imported synchronously.
This plugin requires an LTS Node version (v8.0.0+) and Rollup v1.20.0+.
npm install @rollup/plugin-wasm --save-dev
rollup.config.js configuration file and import the plugin:
;input: 'src/index.js'output:dir: 'output'format: 'cjs'plugins:;
Specifies an array of strings that each represent a WebAssembly file to load synchronously. See Synchronous Modules for a functional example.
The maximum file size for inline files. If a file exceeds this limit, it will be copied to the destination folder and loaded from a separate file at runtime. If
maxFileSize is set to
0 all files will be copied.
Files specified in
sync to load synchronously are always inlined, regardless of size.
Default: (empty string)
A string which will be added in front of filenames when they are not inlined but are copied.
Given the following simple C file:
Compile the file using
emscripten, or the online WasmFiddle tool. Then import and instantiate the resulting file:
The WebAssembly is inlined as a base64 encoded string. At runtime the string is decoded and a module is returned.
Note: The base64 string that represents the WebAssembly within the bundle will be ~33% larger than the original file.
Small modules (< 4KB) can be compiled synchronously by specifying them in the configuration.
This means that the exports can be accessed immediately.
;const instance = ;console;