This guide provides step-by-step instructions for setting up a Rust project to compile to WebAssembly (Wasm) and run it in an HTML file.
-
Open your terminal.
-
Run the following command to install Rust:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
-
Install wasm-pack
curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -
Build the project
wasm-pack build --target web
-
Serve the HTML file which includes the imported Script for ex: you can use python
python3 -m http.server