-
Notifications
You must be signed in to change notification settings - Fork 413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Option to embed .wasm as a base64 string in JavaScript file #831
Comments
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 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 |
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 |
This is a very common requirement, I can't figure out why |
💡 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.The text was updated successfully, but these errors were encountered: