# tauriforge **Repository Path**: zmh/tauriforge ## Basic Information - **Project Name**: tauriforge - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-04 - **Last Updated**: 2026-07-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Tauri Vue App Tauri v2 + Vue 3 + Vite + TypeScript 桌面应用骨架。 ## 开发 ```powershell pnpm install pnpm tauri dev ``` - 改 Vue 文件:Vite HMR 即时刷新 - 改 Rust 文件:自动重编译重启 app - 改 `tauri.conf.json`:需手动重启 `pnpm tauri dev` ## 打包 ```powershell pnpm tauri build # 全部 bundle pnpm tauri build --bundles nsis # 只要 NSIS 安装器(Windows) pnpm tauri build --bundles msi # 只要 MSI(需 WiX) ``` 产物在 `src-tauri/target/release/bundle/`,裸 exe 在 `src-tauri/target/release/`。 ## 前置依赖 ### Windows - **MSVC C++ 构建工具**:装 [Visual Studio Build Tools](https://visualstudio.microsoft.com/visual-cpp-build-tools/),勾选「使用 C++ 的桌面开发」工作负载 - **Rust**:`winget install Rustlang.Rustup`(默认 MSVC 工具链) - **Node.js 20+**:`winget install OpenJS.NodeJS.LTS` - **pnpm**:`npm i -g pnpm` - **WebView2**:Win10/11 默认已装,缺则 `winget install Microsoft.EdgeWebView2Runtime` 验证: ```powershell rustc --version # 应输出 1.96+ cargo --version node --version # v20+ pnpm --version ``` ### macOS ```bash xcode-select --install curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh brew install node npm i -g pnpm ``` WebView 用系统 WebKit,无需额外装。 ### Linux(Ubuntu/Debian 系) ```bash sudo apt update sudo apt install -y libwebkit2gtk-4.1-dev build-essential curl wget file \ libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh sudo apt install -y nodejs npm npm i -g pnpm ``` ## 国内网络环境附加配置(如果 GitHub 下载慢/失败) 首次 `pnpm tauri dev` / `pnpm tauri build` 会从 GitHub 下载: 1. Rust crates(通过 crates.io) 2. WiX 工具(MSI 打包用,~40MB) 3. NSIS 工具(NSIS 打包用,~2MB) ### 加速 Rust crates 下载 编辑 `~/.cargo/config.toml`(没有就新建),加入 rsproxy 镜像: ```toml [source.crates-io] replace-with = 'rsproxy-sparse' [source.rsproxy-sparse] registry = "sparse+https://rsproxy.cn/index/" [net] git-fetch-with-cli = true ``` ### 加速 WiX / NSIS 下载 如果 `pnpm tauri build` 报 `timeout: global` 或 `Peer disconnected`,说明 WiX/NSIS 下不下来。手动用镜像下载并解压: ```powershell # WiX(MSI 用,可选) $zip = "$env:TEMP\wix314-binaries.zip" Invoke-WebRequest "https://ghfast.top/https://github.com/wixtoolset/wix3/releases/download/wix3141rtm/wix314-binaries.zip" -OutFile $zip New-Item -ItemType Directory "$env:LOCALAPPDATA\tauri\WixTools" -Force | Out-Null Expand-Archive $zip -DestinationPath "$env:LOCALAPPDATA\tauri\WixTools" -Force Remove-Item $zip # NSIS(推荐,比 WiX 轻量) $zip = "$env:TEMP\nsis-3.11.zip" Invoke-WebRequest "https://ghfast.top/https://github.com/tauri-apps/binary-releases/releases/download/nsis-3.11/nsis-3.11.zip" -OutFile $zip New-Item -ItemType Directory "$env:LOCALAPPDATA\tauri\NSIS" -Force | Out-Null Expand-Archive $zip -DestinationPath "$env:LOCALAPPDATA\tauri\NSIS" -Force Remove-Item $zip ``` 然后 `pnpm tauri build --bundles nsis` 应能成功。 ## 项目结构 ``` src-tauri/ Rust 后端 src/ main.rs 程序入口(windows_subsystem 配置) lib.rs Tauri Builder + 模块聚合 commands.rs #[tauri::command] 集中放 capabilities/ Tauri v2 权限声明 tauri.conf.json 窗口、应用名、打包配置 src/ Vue 前端 lib/ tauri.ts invoke/event 封装层,前端唯一调 Rust 出口 types.ts Rust 结构体对应 TS 类型(占位) components/ 通用组件(空) views/ 页面级组件(空) assets/styles/ 全局样式 App.vue 根组件 ``` ## 前后端通信 Rust 端用 `#[tauri::command]` 暴露命令,前端通过 `src/lib/tauri.ts` 调用。 新增命令三步: 1. `src-tauri/src/commands.rs` 加 `#[tauri::command]` 函数 2. `src-tauri/src/lib.rs` 的 `invoke_handler!` 宏里注册 3. `src/lib/tauri.ts` 加一个对应的封装函数 错误处理:可能失败的命令返回 `Result`,前端 `try/catch`;纯演示命令(如 `greet`)可直接返回 `T`。 类型同步:Rust 结构体手写对应 TS interface(放 `src/lib/types.ts`),命名一致。骨架阶段不引入 `ts-rs` 自动生成。 ## 跨平台打包 Tauri 不能交叉编译,每个平台的原生包需在对应平台上构建: | 平台 | 产物 | |------|------| | Windows | `.exe`(NSIS 安装器)、`.msi`(需 WiX) | | macOS | `.app`、`.dmg` | | Linux | `.deb`、`.AppImage`、`.rpm` | `tauri.conf.json` 的 `bundle.targets` 设为 `"all"`,各平台自动跳过不支持的格式。