Open Ayrx opened 4 years ago
Note that this must be added to wasm-bindgen first, before it can be added to wasm-pack.
As far as I know, embedding Wasm as a string is the only way to be able to use the same package for browsers, bundlers and Node.js.
Note that if you're using Webpack, you can work around this like so:
In webpack.config.js
:
module.exports = {
module: {
rules: [
{
test: /\.wasm$/,
type: "asset/inline",
},
],
},
plugins: [
new WasmPackPlugin({
extraArgs: "--target web",
}),
],
// ...
};
In your Javascript file:
import initWasm, { /* other wasm imports */ } from "[path to crate]/pkg/index";
import wasmData from "[path to crate]/pkg/index_bg.wasm";
initWasm(wasmData);
Once the promise returned by initWasm
resolves, the WASM module will have been loaded.
Based on this comment, this issue prevents my nextjs project to load parquetjs.
Is there any work around?
I tried @SabrinaJewson 's solution but could not find the required crateDirectory
I should give to the WasmPackPlugin
constructor.
💡 Feature description
wasm-pack
currently generates code similar to the following in--target nodejs
where the.wasm
file is read from the disk.I would like an option to embed the
.wasm
bytes as a base64 encoded string in the generated JS file that is then decoded and loaded when the JS program runs. This would be useful in scenarios where the JS engine is embedded as a scripting environment as the concept of "reading files from disk" does not work.