Closed ranile closed 9 months ago
How do you find it's encoded?. The WASM file is bundled.
Apologies, I should've mentioned this in the issue. I'm using library mode to build a library that exposes an API from the WASM file. The contents of the wasm file are encoded inside the final JS file
my import files is xxx.js and xxx.wasm build from cpp project by emcc
@Yongle-Fu Please try Webpack's asyncWebAssembly
. Does that works?
webpack 5 works
const loadWasm = require('./oz.js'); liboz = await loadWasm()
import addWasmInit from './add.wasm?init'
import loadWasmInit from './oz.wasm?init'
import loadWasm from './oz.js'
// code works
addWasmInit().then((instance) => {
console.log(instance);
console.log(instance.exports.add(1, 2));
});
// code not works, Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #0 module="env" error: module is not an object or function
loadWasmInit().then((instance) => {
console.log(instance);
});
// code not works, another error
const liboz = await loadWasm();
?init
is not related to this plugin, closing.
There should be an option to bundle the WASM as
.wasm
file. At the moment, WASM is encoded as base64 and included in JS. This has several disadvantages, including but not limited to slower execution.Please allow externalizing wasm files