mirror of
https://github.com/yewstack/yew.git
synced 2025-12-08 21:26:25 +00:00
* tree-wide: update links to https://rustwasm.github.io/wasm-bindgen https://rustwasm.github.io/wasm-bindgen -> https://wasm-bindgen.github.io/wasm-bindgen https://rustwasm.github.io/docs/wasm-pack -> https://drager.github.io/wasm-pack/book/ https://rustwasm.github.io/wasm-pack -> https://github.com/drager/wasm-pack
50 lines
1.6 KiB
Plaintext
50 lines
1.6 KiB
Plaintext
---
|
|
title: Using wasm-pack
|
|
---
|
|
|
|
このツールは Rust / Wasm 活動チームによって開発され、WebAssembly のアプリを作るのに使われれるツールで最も活発に開発されているものです。
|
|
コードを`npm`モジュールへパッケージ化するのをサポートし、既存の JavaScript のアプリと簡単に統合できる
|
|
[Webpack plugin](https://github.com/wasm-tool/wasm-pack-plugin)がついています。
|
|
詳しい情報は[the `wasm-pack` documentation](https://drager.github.io/wasm-pack/book/introduction.html)にあります。
|
|
|
|
:::注意
|
|
`wasm-pack`を使う際は`Cargo.toml`の crate-type は`cdylib`である必要があります。
|
|
:::
|
|
|
|
## インストール
|
|
|
|
```bash
|
|
cargo install wasm-pack
|
|
```
|
|
|
|
## ビルド
|
|
|
|
このコマンドは JavaScript ラッパーとアプリの WebAssembly をまとめたものを`./pkg`ディレクトリに生成し、アプリをスタートすることができます。
|
|
This command will produce a bundle in the `./pkg` directory with your app's compiled WebAssembly
|
|
along with a JavaScript wrapper which can be used to start your application.
|
|
|
|
```bash
|
|
wasm-pack build --target web
|
|
```
|
|
|
|
## バンドル
|
|
|
|
ロールアップにについては詳しくは[ガイド](https://rollupjs.org/guide/en/#quick-start)をご覧ください。
|
|
|
|
```bash
|
|
rollup ./main.js --format iife --file ./pkg/bundle.js
|
|
```
|
|
|
|
## サーブ
|
|
|
|
好きなサーバーを使ってください。
|
|
ここではシンプルな Python のサーバーを使ってアプリをサーブします。
|
|
|
|
```bash
|
|
python -m http.server 8000
|
|
```
|
|
|
|
## サポートされているターゲット
|
|
|
|
- `wasm32-unknown-unknown`
|