This example shows you how to use Rust in the Web with webpack v3 (current stable).
-
Install rust.
-
Install WebAssembly target
rustup update
rustup component add wasm32-unknown-unknown --toolchain nightly
- Install wasm-gc (works better than
wasm-opt
from binaryen)
cargo install --git https://github.com/alexcrichton/wasm-gc
- Install node modules
npm i
- Install web server
npm i -g webpack-dev-server
- Build rust source
rustc +nightly --target wasm32-unknown-unknown -O imul.rs --crate-type=cdylib
wasm-gc imul.wasm imul.wasm
- Finalise using webpack
webpack
- Start web server
webpack-dev-server
- Open dev tools / console
$ 2 * 3 = 6