Require WebAssembly modules with Browserify.
Use this Browserify plugin to import WebAssembly binaries.
$ npm i -D wasmifySimply load the plugin:
$ browserify -p wasmifyWhich allows you to import .wasm files in your source:
const sampleModule = require('./sample.wasm')
sampleModule(imports).then(sample => {
sample.instance.exports.main(12, 34)
})Small modules (< 4KB) can be imported synchronously through a sync option.
b.plugin(wasmify, {
sync: [
'sample.wasm'
// ...
]
})This means that the exports can be accessed immediately.
const sampleModule = require('sample.wasm')
const sample = sampleModule(imports)
sample.instance.exports.main(12, 34)