Using the Rust and WebAssembly Working Group's wasm-pack
crate, which lets you compile rust code into WASM, and provides an interface with JavaScript.
📖 Project built from this Mozilla Developer Documentation Tutorial
- Clone the Repo:
git clone https://github.com/jwhogg/rust-wasm-boilerplate
- Build for web using a bundler:
in the main dir:
wasm-pack build --target bundler
- Install webpack:
npm i -D webpack@5 webpack-cli@5 webpack-dev-server@4 copy-webpack-plugin@11
- Serve the site:
cd site
npm run serve
- All done! Navigate to
http://localhost:8080
, and you should see a pop-up:Hello, WebAssembly with npm!