Rustでフロントエンドを作るためのフレームワークYew
Yewとは
Rustを「ユー」(/juː/)。
導入
cargo new hello-yewでプロジェクト作成 - Cargo.tomlの
dependenciesに yewクレートを 追加 cargo update
WASMをビルドする準備
target追加
$ rustup target add wasm32-unknown-unknown
Trunkインストール
Trunkを
$ cargo install --locked trunk
UI作成
html!マクロで
use yew::prelude::*;
// Appコンポーネントを定義
#[function_component(App)]
fn app() -> Html {
html! {
<h1>{"Hello, Yew!"}</h1>
}
}
fn main() {
yew::Renderer::<App>::new().render();
}
Trunkでindex.htmlを
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Hello, Yew!</title>
</head>
<body></body>
</html>
ローカルでアプリのビルド・起動
$ trunk serve --open