This is a simple template without wasm-pack that was forked from wasm-bidgen examples which bridging rust and javascript together.
View the original documentation for this example from wasm-bidgen or View the original compiled example here.
- Make sure you have wasm-bidgen and wasm-bindgen-cli installed (Cargo install ...)
- Initially, add wasm32-unknown-unknown to toolchain. This should only have to be done once:
``` $ rustup target add wasm32-unknown-unknown' ```
- Cargo build with wasm32-unknown-unknown:
``` $ cargo build --target wasm32-unknown-unknown' ```
- Check that you have this file: \\target\wasm32-unknown-unknown\debug\.wasm
- Run the following two commands to make the .wasm file able to be consumed by JS:
``` $ cargo install wasm-bindgen-cli $ wasm-bindgen target\wasm32-unknown-unknown\debug\<program>.wasm --out-dir . ``` This step is where the wasm-bindgen CLI tool postprocesses the input wasm file, making it suitable to use.
- Finally, you can build the example locally with:
``` $ npm run serve ```
Or your other favorite bundler.