Skip to content

Commit 02ee604

Browse files
RynqueGuoJikunvasfvitor
authored
i18n(zh-CN): translate start/project-structure.mdx (tauri-apps#3531)
Co-authored-by: _zhiqiu <[email protected]> Co-authored-by: Ayres Vitor <[email protected]>
1 parent a97166b commit 02ee604

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: 项目结构
3+
i18nReady: true
4+
---
5+
6+
一个 Tauri 项目通常由两部分组成:一个 Rust 项目和一个 JavaScript 项目(可选)。
7+
典型的项目结构如下所示:
8+
9+
```
10+
.
11+
├── package.json
12+
├── index.html
13+
├── src/
14+
│ ├── main.js
15+
├── src-tauri/
16+
│ ├── Cargo.toml
17+
│ ├── Cargo.lock
18+
│ ├── build.rs
19+
│ ├── tauri.conf.json
20+
│ ├── src/
21+
│ │ ├── main.rs
22+
│ │ └── lib.rs
23+
│ ├── icons/
24+
│ │ ├── icon.png
25+
│ │ ├── icon.icns
26+
│ │ └── icon.ico
27+
│ └── capabilities/
28+
│ └── default.json
29+
```
30+
31+
在这种情况下,JavaScript 项目位于顶层目录,而 Rust 项目则位于 `src-tauri/` 文件夹内。
32+
这个 Rust 项目是一个标准的 [Cargo 项目](https://doc.rust-lang.org/cargo/guide/project-layout.html)但包含了一些额外的文件:
33+
34+
- `tauri.conf.json` 是 Tauri 的主要配置文件,其中包含了从应用标识符到开发服务器 URL 的所有配置。
35+
该文件也是 [Tauri CLI](/zh-cn/reference/cli/) 查找 Rust 项目的标记文件。
36+
如需了解更多信息,请参阅 [Tauri 配置](/zh-cn/develop/configuration-files/#tauri-配置)
37+
- `capabilities/` 目录是 Tauri 默认读取[能力(Capability)文件](/zh-cn/security/capabilities/)的文件夹(简而言之,你需要在此处允许命令,才能在 JavaScript 代码中使用它们)。
38+
如需了解更多信息,请参阅[安全](/zh-cn/security/)
39+
- `icons/` 目录是 [`tauri icon`](/zh-cn/reference/cli/#icon) 命令的默认输出目录,通常在 `tauri.conf.json > bundle > icon` 中引用,用于设置应用的图标。
40+
- `build.rs` 包含 `tauri_build::build()`,用于 Tauri 的构建系统。
41+
- `src/lib.rs` 包含 Rust 代码和移动端入口点(标记为 `#[cfg_attr(mobile, tauri::mobile_entry_point)]` 的函数)。
42+
我们不直接在 `main.rs` 中编写代码的原因是,在移动端构建中,你的应用会被编译为库,并通过平台框架加载。
43+
- `src/main.rs` 是桌面端的主入口点,我们在 `main` 函数中调用 `app_lib::run()`,以使用与移动端相同的入口点。
44+
因此,为了简化操作,请勿修改此文件,而是修改 `lib.rs`。请注意,`app_lib` 对应 Cargo.toml 中的 `[lib.name]`
45+
46+
Tauri 的工作方式类似于静态网站托管服务。其构建过程是:首先将 JavaScript 项目编译为静态文件,
47+
然后编译 Rust 项目并将这些静态文件打包进去。
48+
因此,JavaScript 项目的设置与构建静态网站时基本相同。
49+
如需了解更多信息,请参阅[前端配置](/zh-cn/start/frontend/)
50+
51+
如果你只想使用 Rust 代码,只需移除其他所有内容,并将 `src-tauri/` 文件夹作为你的顶级项目,或作为 Rust 工作区的成员即可。
52+
53+
## 下一步
54+
55+
- [添加并配置前端框架](/zh-cn/start/frontend/)
56+
- [Tauri 命令行界面(CLI)参考](/zh-cn/reference/cli/)
57+
- [学习如何开发 Tauri 应用](/zh-cn/develop/)
58+
- [探索扩展 Tauri 的附加功能](/zh-cn/plugin/)

0 commit comments

Comments
 (0)