Can I call functions declared in wasm files from any javascript?
Wasm files were built by wasm-pack with Rust lang, wasm-pack, wasm-bindgen and webpack. They are working fine in the original environment.
I want to use some wasm files for other javascript projects which are not dependent on wasm-pack. For example , a simplest browser hello-world demo project developed in node.js.
Edit: I have read general concepts on how to call wasm functions from javascript. But I cannot apply it to my situation by myself. For example, the article only talk about on a build wasm file. But for my case, there exist many files in the pkg directory of which some files are js files. Can I neglect all such js files in pkg directory?
To me one question appears
But for my case, there exist many files in the pkg directory of which some files are js files. Can I neglect all such js files in pkg directory?
These files are the glue between js
and rust-wasm
. You can neglect them, but then they needs be to replaced with some other glue.
To me simplest is example without-a-bundler
At deployment 3 files are needed:
pkg/without_a_bundler_bg.wasm
,
pkg/without_a_bundler.js
,
index.html
At runtime rust is called from js here: call rust-wasm add function
This function call is done within the wasm-bindgen
glue, so e.g. unknown from dev console. Haven't tried, but still for this small example the generated pkg/without_a_bundler.js
is only 195 lines so for investigation could be manageable to transplant into an other project.