Emscripten-wasm-loader
Wraps up common initialization logic with predefined preprocessor object.
Usage
import { getModuleLoader } from 'emscripten-wasm-loader';
const loader = getModuleLoader(factoryLoader, {dir: 'path', runtimeModule: require('wasm/wasmlibaray') }, { additional: ''});
getModuleLoader
is higher order function returns actual module loader.
getModuleLoader<T, R extends AsmRuntimeType>(
factoryLoader: (runtime: R) => T,
asm: { dir: string | null; runtimeModule: runtimeModuleType },
module?: stringMap
) => moduleLoaderType<T>;
type moduleLoaderType<T> = (binaryEndpoint?: string, environment?: ENVIRONMENT) => Promise<T>;
factoryLoader
is function to create actual instance of module using initialized wasm binary runtime. asm
requires 2 values, dir
is absolute path of wasm
or mem
binary location, and runtimeModule
is function loaded via require
to emscripten preamble js for wasm binaries. It expected wasm binary should be built with MODULARIZE=1
option so runtimeModule
can be function to be executed. In case of dir
, it's node.js only option and will be ignored on browser environment. Lastly module
is object to be inherited when execute runtimeModule
. Emscripten's modularized preamble construct scoped wasm runtime module named Module
, allows to have predefined object if needed. Internally getModuleLoader
augments given object and set default interfaces like initializeRuntime
.