Rust WebAssembly Cheat Sheet

Last Updated: November 21, 2025

Targets & Toolchain

Tool Role
wasm-pack Build + bundle for npm or bundlers
wasm-bindgen Generate JS bindings and glue code
cargo + target wasm32-unknown-unknown Compile core wasm module

Commands

wasm-pack build --target web
Produce WASM + JS wrappers
wasm-bindgen pkg --target bundler
Emit modules consumable by bundlers
wasm-opt -O3 pkg/module_bg.wasm
Optimize binary size

Runtime Tips

Manage memory with `wasm-pack` exports, reuse JS event loops, and avoid panics by returning results to JS.

💡 Pro Tip: Keep modules small, inline critical code, and minimize allocations crossing the wasm boundary.
← Back to Programming Languages | Browse all categories | View all cheat sheets