Skip to content
📦✨ your favorite rust -> wasm workflow tool!
Branch: master
Clone or download
ashleygwilliams Merge pull request #588 from rustwasm/crates-badge
feat(doc): add crates.io badge to readme
Latest commit 15974fe Mar 16, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github Add rust-toolchain file set to nightly Nov 29, 2018
binary-install feat(binstall): 0.0.2 Mar 16, 2019
docs feat(release): 0.7.0 Mar 16, 2019
src fix: merge Mar 15, 2019
tests/all Tweak output formatting slightly and location Mar 15, 2019
.appveyor.yml
.gitignore
.travis.yml
CHANGELOG.md
CODE_OF_CONDUCT.md feat(coc): add rust coc Apr 18, 2018
CONTRIBUTING.md
Cargo.lock feat(binstall): 0.0.2 Mar 16, 2019
Cargo.toml
LICENSE-APACHE feat(doc): add licenses Feb 13, 2018
LICENSE-MIT feat(doc): add licenses Feb 13, 2018
README.md feat(doc): add crates.io badge to readme Mar 16, 2019
clippy.toml
demo.gif

README.md

📦✨ wasm-pack

Your favorite rust -> wasm workflow tool!

Build Status Build status crates.io

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!

demo

🔮 Prerequisities

This project requires Rust 1.30.0 or later.

🎙️ Commands

  • build: Generate an npm wasm pkg from a rustwasm crate
  • test: Run browser tests
  • pack and publish: Create a tarball of your rustwasm pkg and/or publish to a registry

📝 Logging

wasm-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

👯 Contributing

Read our guide on getting up and running for developing wasm-pack, and check out our contribution policy.

⚡ Quickstart Guide

  1. Write a crate in Rust.
  2. Add wasm-bindgen to your Cargo.toml:
[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "0.2"
  1. Add this to the top of your src/lib.rs:
extern crate wasm_bindgen;

use wasm_bindgen::prelude::*;
  1. Annotate your public functions with #[wasm_bindgen], for example:
#[wasm_bindgen]
extern {
    pub fn alert(s: &str);
}

#[wasm_bindgen]
pub fn greet(name: &str) {
    alert(&format!("Hello, {}!", name));
}
  1. Install this tool: cargo install wasm-pack
  2. Run wasm-pack build, optionally, pass a path to a dir or a scope (see above for details)
  3. This tool generates files in a pkg dir
  4. To publish to npm, run wasm-pack publish. You may need to login to the registry you want to publish to. You can login using wasm-pack login.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.