fork of https://github.com/rustwasm/wasm-pack for the needs of NextGraph.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Mason Stallmo d84aae3b64 Refactor: fix clippy warnings 6 years ago
.github Add rust-toolchain file set to nightly 6 years ago
binary-install binary-install: don't make getting a binary from a download infallible 6 years ago
docs doc: Update to 2019 6 years ago
src Refactor: fix clippy warnings 6 years ago
tests/all binary-install: don't make getting a binary from a download infallible 6 years ago
.appveyor.yml CI: run normal tests and cargo tests separately 7 years ago
.gitignore feat(ignore): remove wasm-pack.log 6 years ago
.travis.yml Merge pull request #433 from fitzgen/update-mdbook 7 years ago
CHANGELOG.md feat(changelog): s/Carol/Cargo 6 years ago
CODE_OF_CONDUCT.md feat(coc): add rust coc 7 years ago
CONTRIBUTING.md Add link to help article on setting up a global .gitignore 7 years ago
Cargo.lock binary-install: don't make getting a binary from a download infallible 6 years ago
Cargo.toml v0.6.0 6 years ago
LICENSE-APACHE feat(doc): add licenses 7 years ago
LICENSE-MIT feat(doc): add licenses 7 years ago
README.md doc(logs): document env_logger setup 6 years ago
clippy.toml Refactor: fix clippy warnings 6 years ago
demo.gif v0.5.0 7 years ago

README.md

📦 wasm-pack

Your favorite rust -> wasm workflow tool!

Build Status Build status

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 and publish rust-generated WebAssembly to the npm registry to be used alongside any other javascript package 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

  • init ( DEPRECATED): This command has been deprecated since release 0.5.0, in favor of build. 0.4.2 and previous use this command.
  • build: Generate an npm wasm pkg from a rustwasm crate
  • 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.