项目结构
一个 Tauri 项目通常由两部分组成,一个 Rust 项目和一个 JavaScript 项目(可选),并且通常的设置大致如下:
🌐 A Tauri project is usually made of 2 parts, a Rust project and a JavaScript project (optional), and typically the setup looks something like this:
.├── package.json├── index.html├── src/│ ├── main.js├── src-tauri/│ ├── Cargo.toml│ ├── Cargo.lock│ ├── build.rs│ ├── tauri.conf.json│ ├── src/│ │ ├── main.rs│ │ └── lib.rs│ ├── icons/│ │ ├── icon.png│ │ ├── icon.icns│ │ └── icon.ico│ └── capabilities/│ └── default.json在这种情况下,JavaScript 项目位于顶层,Rust 项目位于 src-tauri/ 内,Rust 项目是一个普通的 Cargo 项目,并包含一些额外的文件:
🌐 In this case, the JavaScript project is at the top level, and the Rust project is inside src-tauri/,
the Rust project is a normal Cargo project with some extra files:
tauri.conf.json是 Tauri 的主配置文件,它包含从应用标识符到开发服务器 URL 的所有内容,这个文件也是 Tauri CLI 用来找到 Rust 项目的标记,想了解更多,请参阅 Tauri 配置capabilities/目录是 Tauri 默认读取 capability files 的文件夹(简单来说,你需要在这里允许命令以便在你的 JavaScript 代码中使用它们),要了解更多内容,请参阅 Securityicons/目录是tauri icon命令的默认输出目录,它通常在tauri.conf.json > bundle > icon中被引用,并用于应用的图标build.rs包含tauri_build::build(),它被用于 tauri 的构建系统src/lib.rs包含 Rust 代码和移动入口点(标记为#[cfg_attr(mobile, tauri::mobile_entry_point)]的函数),我们不直接在main.rs中编写的原因是因为我们在移动构建中将你的应用编译为库,并通过平台框架加载它们src/main.rs是桌面的主要入口点,我们在main中运行app_lib::run()以使用与移动端相同的入口点,所以为了保持简单,不要修改此文件,而是修改lib.rs。注意,app_lib对应于 Cargo.toml 中的[lib.name]。
Tauri 的工作方式类似于静态网站托管,它的构建方式是先将你的 JavaScript 项目编译成静态文件,然后再编译将这些静态文件打包的 Rust 项目,因此 JavaScript 项目的设置基本上和构建静态网站时一样。要了解更多信息,请参见 前端配置
🌐 Tauri works similar to a static web host, and the way it builds is that you would compile your JavaScript project to static files first, and then compile the Rust project that will bundle those static files in, so the JavaScript project setup is basically the same as if you were to build a static website, to learn more, see Frontend Configuration
如果你只想使用 Rust 代码工作,只需移除其他所有内容,并将 src-tauri/ 文件夹用作你的顶层项目或你的 Rust 工作区的一个成员
🌐 If you want to work with Rust code only, simply remove everything else and use the src-tauri/ folder as your top level project or as a member of your Rust workspace
🌐 Next Steps
Tauri 中文网 - 粤ICP备13048890号
Nodejs.cn 旗下网站