Closed transitive-bullshit closed 6 years ago
Unfortunately it won't be effecient. The whole point of WebAssembly is that it can be parsed fast. If you put it back into JavaScript file, you lose main benefits - compactness and small parsing time.
If you wish you can include vmsg.wasm
with e.g. arraybuffer-loader:
const buffer = require("arraybuffer!./vmsg.wasm");
const blob = new Blob([buffer], {type: "application/wasm"});
const wasmURL = URL.createObjectURL(blob);
that will work.
I ended up doing something similar for react-mp3-recorder. This doesn't seem particularly efficient, however.
I've just tried, seems like you can just pass data URI to fetch directly:
> url = 'data:application/wasm;base64,' + btoa("123")
"data:application/wasm;base64,MTIz"
> fetch(url).then(res => res.arrayBuffer()).then(b => console.log(new Uint8Array(b)))
Uint8Array(3) [49, 50, 51]
Good call -- just updated my impl.
Can we close this now?
It'd be great if
vmsg.wasm
was embedded directly via an ArrayBuffer or as a compile-time step.Having the end user reference the URL of
vmsg.wasm
is pretty clunky, though I understand why it's setup that way at the moment.