Skip to content
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

Pass wasm-buffer to importHook() #2

Closed
wants to merge 1 commit into from

Conversation

njam
Copy link

@njam njam commented May 17, 2020

I wanted to inline the WASM file as a byte array into the JavaScript.

By passing the WASM file contents to importHook() I could make it work like this:

importHook: function (path, buffer) {
  let array = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
  return `Uint8Array.from([${array.toString()}])`
},

I guess thanks to your changes in rustwasm/wasm-bindgen#1996.

Wdyt about adding this parameter to importHook()?

@njam
Copy link
Author

njam commented May 28, 2020

mentioning @Pauan in case you didn't receive a notification

@Pauan
Copy link
Collaborator

Pauan commented Jun 4, 2020

@njam Sorry for the delay. Just passing an argument to importHook isn't good enough, because it also has to not emit the .wasm file.

So I think it would be better to have it as a separate option (such as inlineWasm: true). It could also do things like use base64 encoding, to reduce the file size.

@Pauan
Copy link
Collaborator

Pauan commented Jun 4, 2020

I just released version 1.0.3 which includes an inlineWasm: true option. This will inline it as a base64 string, which should be much more efficient than using an array.

@Pauan Pauan closed this Jun 4, 2020
@njam
Copy link
Author

njam commented Jun 4, 2020

Yes much nicer! Thanks!

Link to the commit 541bd9d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants