官方文档
使用前
设备和操作系统
macOS Monterey v12.2.1 (macbook air 2017)
安装本地环境
- 确保 xcode 工具已经安装好,没有安装的话,执行
xcode-select --install
. - 安装 rust 环境
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
,安装好后会提示:
stable-x86_64-apple-darwin installed - rustc 1.59.0 (9d1b2106e 2022-02-23)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).
To configure your current shell, run:
source $HOME/.cargo/env
- 根据安装好后的提示,叫我们重启下终端或者刷新下环境变量,那么我们就刷新下,输入
source $HOME/.cargo/env
- 输入
rustc --version
,我的提示rustc 1.59.0 (9d1b2106e 2022-02-23)
,说明安装好了 cargo install tauri-bundler --force
yarn create tauri-app
选择vite+react+typescript
- 添加启动命令到
package.json
"start": "tauri dev"
yarn start
等待安装编译,首次启动可能花费数分钟时间
集成到现有项目
前4步同上
5 .在项目根目录下yarn add -D @tauri-apps/cli
- 添加启动命令到
package.json
"scripts": {
"tauri": "tauri",
"start": "tauri dev",
}
yarn add @tauri-apps/api
yarn tauri init
- 修改
scr-tauri/tauri.conf.json
里的"devPath"
为本地的dev
端口 - 修改
"beforeDevCommand": "yarn dev",
这样就在启动web
服务后,再启动tauri
yarn start
初次启动会编译很多文件,稍等片刻