- 使用
rustup
安裝 rust
。
- 安裝此工具。
- 執行
wasm-pack new hello-wasm
。
cd hello-wasm
- 執行
wasm-pack build --target web
。
- 此工具會在
pkg
目錄中產生檔案
- 匯入它:
import init, { greet } from "./pkg/hello_wasm.js"
,初始化它:await init()
,然後使用它:greet()
- 要發布到 npm,請執行
wasm-pack publish
。您可能需要登入您要發布的 registry。您可以使用 wasm-pack login
登入。