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.
 
 
Ashley Williams 8ed83d067c feat(contrib): update the contributing.md 7 years ago
.github feat(emojify template) Make PR template 100% emoji 7 years ago
src fix(style): appease cargo fmt 7 years ago
tests feat(refactor): Furthers previous refactor, by moving 7 years ago
.appveyor.yml feat(test): add appveyor 7 years ago
.gitignore add target/ to gitignore 7 years ago
.travis.yml feat(test): we only work on nightly now 7 years ago
CODE_OF_CONDUCT.md add Code of Conduct 7 years ago
CONTRIBUTING.md feat(contrib): update the contributing.md 7 years ago
Cargo.lock feat(pbar): Add global progress bar to write to 7 years ago
Cargo.toml feat(pbar): Add global progress bar to write to 7 years ago
LICENSE-APACHE feat(doc): add licenses 7 years ago
LICENSE-MIT feat(doc): add licenses 7 years ago
README.md Merge pull request #64 from ashleygwilliams/demo 7 years ago
demo.gif feat(doc): add demo gif to readme 7 years ago

README.md

📦 wasm-pack

pack up the wasm and publish it to npm!

Build Status Build status

the goal of this project is to create a portable command line tool for publishing compiled wasm projects to the npm registry for the consumption of js devs using the npm CLI, yarn, or any other CLI tool that interfaces with the npm registry.

this project is a part of the rust-wasm group. you can find more info by visiting that repo!

demo

🔮 prerequisities

this project is written in rust. get rust to work on this project.

if you want to publish packages, you'll also need an account on npm and have node/npm installed.

🏃 up and running

  1. fork and clone this repository
  2. install node/npm
  3. cd wasm-pack
  4. cargo run

💃 commands

  • help: display available commands
  • 🐣 init: create necessary files for js interop and npm publishing
    • optionally pass a path to a dir that contains a Cargo.toml, e.g.:
      wasm-pack init examples/js-hello-world
      
    • optionally pass a scope name to generate a package.json for a scoped pkg, e.g.:
      wasm-pack init examples/scopes-hello-world --scope test
      
      generates a package.json for an npm package called @test/scopes-hello-world
  • 🍱 pack: create a tarball but don't push to the npm registry (see https://docs.npmjs.com/cli/pack)
  • 🎆 publish: create a tarball and publish to the npm registry (see https://docs.npmjs.com/cli/publish)

how to use

  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:
  #![feature(proc_macro, wasm_import_module, wasm_custom_section)]

  extern crate wasm_bindgen;

  use wasm_bindgen::prelude::*;
  1. annotate your public functions with #[wasm_bindgen], for example:
#[wasm_bindgen]
extern {
    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 init, 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 (making sure you are logged in with npm)