mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* add prettier * ci * run prettier * run prettier in CI * run prettier --write * ignore README.md * specify googleAnalytics * fmt * npm run write-translations * fmt * ignore i18n json files they're autogenerated and don't like being formatted * post merge fixes & some updates * post merge fixes
42 lines
1.2 KiB
Plaintext
42 lines
1.2 KiB
Plaintext
# 使用 wasm-pack
|
|
|
|
这个工具由 Rust / Wasm 工作组开发维护,并且是现在最为活跃的 WebAssembly 应用开发工具。 它支持将代码打包成 `npm` 模块,并且随附了 [Webpack 插件](https://github.com/wasm-tool/wasm-pack-plugin),可以轻松的与已有的 JavaScript 应用结合。可以点击[这里](https://rustwasm.github.io/docs/wasm-pack/introduction.html)了解更多。
|
|
|
|
:::note
|
|
注:如果使用 `wasm-pack`作为开发工具,`Cargo.toml` 中的 `crate-type` 需要为 `cdylib`
|
|
:::
|
|
|
|
## 安装
|
|
|
|
```bash
|
|
cargo install wasm-pack
|
|
```
|
|
|
|
## 构建
|
|
|
|
这条命令将在工程根目录下的 `./pkg` 目录中生成打包后的应用,其中包含应用的 WebAssembly 文件以及用来启动应用的 JavaScript 包装器。
|
|
|
|
```bash
|
|
wasm-pack build
|
|
```
|
|
|
|
## 打包
|
|
|
|
关于 Rollup 的更多信息,请查看这篇[指南](https://rollupjs.org/guide/en/#quick-start)
|
|
|
|
```bash
|
|
rollup ./main.js --format iife --file ./pkg/bundle.js
|
|
```
|
|
|
|
## 部署
|
|
|
|
选取你喜爱的服务器。这里我们使用一个简单的 Python 服务器来将项目部署到:[http://\[::1\]:8000](http://[::1]:8000)。
|
|
|
|
```bash
|
|
python -m SimpleHTTPServer 8080
|
|
```
|
|
|
|
## 支持生成的目标代码
|
|
|
|
- `wasm32-unknown-unknown`
|