worker-rust
添加target:wasm32-unknown-unknown
rustup target add wasm32-unknown-unknown
info: downloading component 'rust-std' for 'wasm32-unknown-unknown'
info: installing component 'rust-std' for 'wasm32-unknown-unknown'
19.0 MiB / 19.0 MiB (100 %) 14.9 MiB/s in 1s ETA: 0s
安装worker-build
注意看 wrangler.toml
,它每次构建都会运行:
[build]
command = "cargo install -q worker-build && worker-build --release"
不如我们直接:
cargo install worker-build
然后修改 wrangler.toml
:
[build]
command = "worker-build --release"
安装wasm-pack
cargo install wasm-pack
Cargo安装可能会报openssl编译错误,建议直接下载:
https://github.com/rustwasm/wasm-pack
https://rustwasm.github.io/wasm-pack/
安装wasm-bindgen-cli
这是每次运行npm run dev
的输出:
[INFO]: ⬇️ Installing wasm-bindgen...
Downloaded wasm-bindgen-cli v0.2.84
不如直接:
cargo install wasm-bindgen-cli
这样它就不会再次检测下载了
npm run dev
$ npm run dev
> template-worker-rust@0.0.0 dev F:\worker\worker-rust
> wrangler dev --local
⛅️ wrangler 2.16.0 (update available 2.17.0)
-------------------------------------------------------
Running custom build: cargo install -q worker-build && worker-build --release
[INFO]: 🎯 Checking for the Wasm target...
[INFO]: 🌀 Compiling to Wasm...
Compiling proc-macro2 v1.0.56
Compiling quote v1.0.26
Compiling unicode-ident v1.0.8
Compiling syn v1.0.109
Compiling wasm-bindgen-shared v0.2.84
Compiling log v0.4.17
Compiling cfg-if v1.0.0
Compiling once_cell v1.17.1
...