wasm-nanoid
Tutorial for your first wasm package.
docker run -v "$PWD":/usr/src/myapp -w /usr/src/myapp --rm --interactive --tty stereobooster/rust-wasmUSER=stereobooster cargo generate --git https://github.com/rustwasm/wasm-pack-templatecd wasm-nanoid
Use your github handle instead of mine (USER=stereobooster
).
Edit Cargo.toml
:
description = "nanoid implemented in wasm"repository = "https://github.com/stereobooster/wasm-nanoid"license = "MIT"
Edit README.md
. Run:
wasm-pack init
Add to .gitignore
:
*.log
pkg/*
Commit (you may want to do this in different terminal, because git inside Docker is not configured).
git add .
git commit -m "initial commit"
I want to build simple thing, so I will reuse existing Nano ID package (they call it crate in Rust).
Add dependency to Cargo.toml (this is like a package.json
for npm):
nanoid = "0.2.0"
Edit src/lib.rs
:
extern crate nanoid; use wasm_bindgen::prelude::*; pub fn simpleNanoid() -> JsValue { JsValue::from_str(&nanoid::simple())}