這是 wasm-pack未發佈文件,已發佈的文件可在 Rust 和 WebAssembly 主要文件網站 上取得。這裡記錄的功能可能無法在 wasm-pack 的發行版本中使用。

快速入門

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