wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

Embedding WebAssembly in Javascript code

Open yoshida-valuesccg opened this issue 3 years ago • 7 comments

💡 Feature description

I wish wasm-pack could do something like this. The feature is almost the same as doing wasm-pack build --target nodejs except, instead of doing

const path = require('path').join(__dirname, 'xxx_bg.wasm');
const bytes = require('fs').readFileSync(path);

do

// convert wasm file into base64 and embed it
const base64Wasm = "AGFzbQEAAAABBwFgAn9/AX8DAgEABwcBA2FkZAAACgkBBwAgACABags=";
const bytes = base64Decode(base64Wasm);

This is very helpful because I dont have to worry about .wasm file in both nodejs and web.

yoshida-valuesccg avatar Oct 24 '21 07:10 yoshida-valuesccg

+1, I've been doing this by hand and would love a build system that does it automatically.

jmole avatar Oct 25 '21 06:10 jmole

See also #831. I posted a workaround there that works with Webpack.

SabrinaJewson avatar Oct 26 '21 20:10 SabrinaJewson

so you proposing essentially --target inline and base64 encoded inline wasm loading?

sassman avatar Nov 17 '21 01:11 sassman

@sassman that's the gist of it, at least from my perspective. It offers a nice "one-file" solution to incorporate wasm into a webpage.

jmole avatar Nov 19 '21 19:11 jmole

I've been searching something like this for days. Has anyone done this with binding any canvas functions?

expertfox avatar Jan 13 '22 08:01 expertfox

Would love to have this!

xiaohk avatar Sep 21 '22 04:09 xiaohk

+1, I've been doing this by hand and would love a build system that does it automatically.

Hey @jmole, how did you do this by hand?

xiaohk avatar Sep 21 '22 04:09 xiaohk