Wasm build, made easy
Warning
It's in early development status, use in your own risk.
- Build a set of code that can run seamlessly in Node.js, Deno, Bun, and browsers.
- No setup needed, just use directly.
- The generated package.json in pretty order.
- Add parameter validation to functions.
Requires Node.js >=20.19.0.
pnpm install -D wasmupUse the same ESM API in all runtimes:
importinit,{hello_world}from"your-wasm-package"awaitinit()console.log(hello_world())For sync initialization:
initSyncis only supported in Node.js, Bun and Deno.initSyncis not supported in browsers.
For browser deployment:
- Keep
index_bg.wasmaccessible by URL. index_bg.wasmshould be deployed next to the generated JS entry (or with an equivalent URL mapping).
The Wasmup configuration file may be named any of the following:
wasmup.config.jswasmup.config.cjswasmup.config.mjswasmup.config.tswasmup.config.mtswasmup.config.ctswasmup.config.json
It should be placed in the root directory of your project and export an configuration objects. Here’s an example:
import{defineConfig}from"wasmup"exportdefaultdefineConfig({clean: true,output: "packages/toml-edit-js",scope: "rainbowatcher",})you can pass wasm-opt params by config in Cargo.toml, details ref to this link: cargo-toml-configuration
[package.metadata.wasm-pack.profile.release]
wasm-opt = [
# Optimize level 4"-O4",
# Run passes to convergence, continuing while binary size decreases"--converge",
"--strip-debug",
"--strip-dwarf",
# flattens out code, removing nesting"--flatten",
# inline small functions"--inlining",
# removes unreachable code"--dead-code-elimination",
"--minify-imports-and-exports-and-modules",
# Grand Unified Flow Analysis"--gufa",
]MIT © Made by ❤️
{ // ..."scripts": { "build": "wasmup build --clean .", }, }