webassembly-loader
this loader can also be used as a library ↙ see who use this?
tl;dr -- see examples
Motivation
Minimum Requirements
- Node v8
- Webpack v4
Installation
npm install webassembly-loader --save-dev
or
yarn add webassembly-loader --dev
Options
export
How wasm code would be exported. (see examples)
- Type:
string
- Default:
async
- Expected value:
buffer
will export wasm code as Buffermodule
will export wasm code as WebAssembly.Moduleinstance
will export wasm code as WebAssembly.Instanceasync
will instantiate wasm code asynchronously, return promise of both WebAssembly.Module and WebAssembly.Instanceasync-module
will compile wasm code asynchronously, return promise of WebAssembly.Moduleasync-instance
will instantiate wasm code asynchronously, return promise of WebAssembly.Instance
webpack.config.js
moduleexports = rules: test: /\.wasm$/ type: "javascript/auto" use: loader: "webassembly-loader" options: export: "async"
tips: you can use query parameter to change export mode on demand
Examples
See the test cases and example projects in *.test.ts and examples for more insight.
{export: 'buffer'}
; WebAssembly;
{export: 'module'}
; const instance = wasmModule;consoleinstanceexports; // 3
{export: 'instance'}
; consolewasmexports; // 3
{export: 'async'}
; ;
{export: 'async-instance'}
; ;
{export: 'async-module'}
; ;
Who use this?
- rs-jest
- rollup-plugin-rust
- [add yours 😉]
Contributing
- CONTRIBUTING.md for how you can make contribution
- HACKING.md for technical details