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.
![]() |
7 years ago | |
---|---|---|
src | 7 years ago | |
tests | 7 years ago | |
.appveyor.yml | 7 years ago | |
.gitignore | 7 years ago | |
.travis.yml | 7 years ago | |
CODE_OF_CONDUCT.md | 7 years ago | |
CONTRIBUTING.md | 7 years ago | |
Cargo.lock | 7 years ago | |
Cargo.toml | 7 years ago | |
LICENSE-APACHE | 7 years ago | |
LICENSE-MIT | 7 years ago | |
README.md | 7 years ago |
README.md
📦✨ wasm-pack
pack up the wasm and publish it to npm!
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!
🔮 prerequisities
this project is written in rust. get rust to work on this project.
🏃♀️ up and running
- fork and clone this repository
cd wasm-pack
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.:
generates awasm-pack init examples/scopes-hello-world --scope test
package.json
for an npm package called@test/scopes-hello-world
- optionally pass a path to a dir that contains a
to be implemented
- 🍱
pack
: create a tarball but don't push to the npm registry [NOT IMPLEMENTED] - 🎆
publish
: create a tarball and publish to the npm registry [NOT IMPLEMENTED]
⚙️ how to use
- write a crate in Rust.
- add
wasm-bindgen
to yourCargo.toml
:
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = { git = 'https://github.com/alexcrichton/wasm-bindgen' }
- add this to the top of your
src/lib.rs
:
#![feature(proc_macro)]
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
- 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));
}
- install this tool:
cargo install wasm-pack
- run
wasm-pack init
, optionally, pass a path to a dir or a scope (see above for details) - this tool generates files in a
pkg
dir. to publish to npm,cd pkg
and thennpm publish
(in the future you'll be able to use this tool to publish)