Allows running wasm applications and examples as simply as:
cargo run-wasm crate_name
or
cargo run-wasm --example example_name
In the background it:
- Compiles the rust project to wasm
- Runs wasm-bindgen
- Generates an index.html that runs the wasm.
- Launches a tiny webserver to serve index.html + your wasm
- Setup your wasm runnable project as a crate within a cargo workspace
- Create a crate in the workspace named run-wasm with:
Cargo.toml
:
[package]
name = "run-wasm"
version = "0.1.0"
edition = "2021"
[dependencies]
cargo-run-wasm = "0.1.0"
main.rs
:
fn main() {
cargo_run_wasm::run_wasm();
}
- Create a
.cargo/config
file containing:
[alias]
run-wasm = "run --release --package run-wasm --"
- Thats it, you can now run the commands described earlier. You can also run
cargo run-wasm --help
to view all the possible flags.
- cross platform
- 0 external dependencies
- better UX + more robust than anything hacked together with bash/powershell/bat
- wasm-bindgen-cli version is always in sync with wasm-bindgen version because
cargo update
updates both of them at the same time thanks to being in the same workspace
cargo-run-wasm is not available as a cargo custom command as that would cause:
- issues with mismatches between wasm-bindgen versions
- issues with keeping a stable interface with the wasm app
- gives the idea that the command is compatible with every project that uses wasm which is not the case.
Licensed under either of
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.