Your favorite rust -> wasm workflow tool!
This tool seeks to be a one-stop shop for building and working with rust-
generated WebAssembly that you would like to interop with JavaScript, in the
browser or with Node.js. wasm-pack
helps you build rust-generated
WebAssembly packages that you could publish to the npm registry, or otherwise use
alongside any javascript packages in workflows that you already use, such as [webpack]
or [greenkeeper].
This project is a part of the [rust-wasm] group. You can find more info by visiting that repo!
This project requires Rust 1.30.0 or later.
build
: Generate an npm wasm pkg from a rustwasm cratetest
: Run browser testspack
and publish
: Create a tarball of your rustwasm pkg and/or publish to a registrywasm-pack
uses [env_logger
] to produces logs when wasm-pack
runs.
To configure your log level, use the RUST_LOG
environment variable. For example:
RUST_LOG=info wasm-pack build
Read our [guide] on getting up and running for developing wasm-pack
, and
check out our [contribution policy].
Add wasm-bindgen
to your Cargo.toml
:
```toml [lib] crate-type = ["cdylib"]
[dependencies] wasm-bindgen = "0.2" ```
Add this to the top of your src/lib.rs
:
```rust extern crate wasm_bindgen;
use wasm_bindgen::prelude::*; ```
Annotate your public functions with #[wasm_bindgen]
, for example:
```rust
extern { pub fn alert(s: &str); }
pub fn greet(name: &str) { alert(&format!("Hello, {}!", name)); } ```
Install this tool: cargo install wasm-pack
wasm-pack build
, optionally, pass a path to a dir or a scope (see above for details)pkg
dirwasm-pack publish
. You may need to login to the
registry you want to publish to. You can login using wasm-pack login
.