Menci / vite-plugin-wasm

Add WebAssembly ESM integration (aka. Webpack's `asyncWebAssembly`) to Vite and support `wasm-pack` generated modules.
MIT License
281 stars 16 forks source link

Load wasm library in obsidian.md plugin using base64 #58

Closed tmayoff closed 2 months ago

tmayoff commented 2 months ago

I have an obsidian plugin I'd like to be able to load a wasm library from. I was able to get it to load using this vite plugin. At first it wouldn't load with this error: GET app://obsidian.md/assets/recipe_rs_bg.wasm net::ERR_FILE_NOT_FOUND, which I could solve by manually specifying the location of the .wasm file using obsidian's API to get the correct path. However it doesn't seem I can distribute the .wasm anyways with the plugin.

Is there a way to force the base64 to hopefully not need to have a separate .wasm file? If that's what the base64 encoding is doing here

tmayoff commented 2 months ago

Alright so I seem to have gotten it working.

Import the wasm library like so:

import initWasm from 'recipe-rs';
import wasmData from 'recipe-rs/recipe_rs_bg.wasm?url';

and load it:

await initWasm(wasmData);