sycamore
0.安装rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
在中国大陆用替代方法
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rust.sh
sed -i 's|static.rust-lang.org|mirrors.ustc.edu.cn/rust-static|g' rust.sh
export RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup
chmod a+x rust.sh
./rust.sh
安装完成后
echo "RUSTUP_DIST_SERVER=https://mirrors.tuna.tsinghua.edu.cn/rustup" >> ~/.cargo/env
- 添加wasm编译器
rustup target add wasm32-unknown-unknown
- 安装Trunk
Trunk是Sycamore的构建工具,类似于Javascript前端开发中的webpack
cargo install --locked trunk
Sycamore开发团队也在尝试开发专用的构建工具,但目前还是推荐使用 Trunk
- 建立一个新的sycamore项目
cargo new hello-sycamore
cd hello-sycamore
cargo add [email protected]
- 编辑项目中的 src/main.rs, 用下面的内容完全替代它
use sycamore::prelude::*; fn main() { sycamore::render(|| "Hello, world!".into()); }
- 在项目的根目录下创建 index.html, 内容为
<!DOCTYPE html> <html> <head></head> <body></body> </html>
- 运行
trunk serve
将会构建你的应用,并在监听在 本机的8080端口,你用浏览器打开 http://localhost:8080 即可看到