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!
this project is written in rust. [get rust] to work on this project.
cd wasm-pack
cargo run
help
: display available commandsinit
: create necessary files for js interop and npm publishing
Cargo.toml
, e.g.:
wasm-pack init examples/js-hello-world
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 [NOT IMPLEMENTED]publish
: create a tarball and publish to the npm registry [NOT IMPLEMENTED]add wasm-bindgen
to your Cargo.toml
:
```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
:
```rust
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*; ```
annotate your public functions with #[wasm_bindgen]
, for example:
```rust
extern { fn alert(s: &str); }
pub fn greet(name: &str) { alert(&format!("Hello, {}!", name)); } ```
install this tool: cargo install wasm-pack
wasm-pack init
, optionally, pass a path to a dir or a scope (see above for details)pkg
dir. to publish to npm, cd pkg
and then npm publish
(in the future you'll be able to use this tool to publish)