Using wasm-pack

This tool was created by the Rust / Wasm Working Group and is the most actively developed tool for building WebAssembly applications. It supports packaging code into npm modules and has an accompanying Webpack plugin for easy integration with an existing JavaScript application. More information is given in the wasm-pack documentation.

Note that the crate-type in your Cargo.toml will need to be cdylib when using wasm-pack


cargo install wasm-pack


This command will produce a bundle in the ./pkg directory with your app's compiled WebAssembly along with a JavaScript wrapper which can be used to start your application.

wasm-pack build --target web


For more information on Rollup visit this guide

rollup ./main.js --format iife --file ./pkg/bundle.js


Feel free to use your preferred server. Here we use a simple python server to serve to

python -m http.server 8000

Supported Targets

  • wasm32-unknown-unknown