A detailed tutorial for kick starting a Rust and WebAssembly project using wasm-pack.
📚 Read this template tutorial! 📚
This template is designed for compiling Rust libraries into WebAssembly and publishing the resulting package to NPM.
Be sure to check out other wasm-pack
tutorials online for other
templates and usages of wasm-pack
.
Learn more about cargo generate
here.
cargo generate --git https://github.com/rustwasm/wasm-pack-template.git --name my-project
cd my-project
After Rust code is ready to go, auto-generate the Javascript FFI from the Rust src folder by running
wasm-pack build
This will then generate the folder ...
npm init wasm-app www
cd www
npm install (to install webserver)
The www folder will generate a template to connect Javascript/HTML webpage rendering and connect it to the auto-generated Javascript FFI binary.
The index.js
file can then be used to display the game. And also, the server will be on localhost:8080
.
After you cd into the www
folder,
npm run start
wasm-pack test --headless --firefox
wasm-pack publish
wasm-bindgen
for communicating between WebAssembly and JavaScript.console_error_panic_hook
for logging panic messages to the developer console.wee_alloc
, an allocator optimized for small code size.