Skip to content

打包分发

tauri build 先构建前端静态资源,再编译 Rust 并按平台生成安装包。

bash
pnpm tauri build

也可以拆开:

bash
pnpm tauri build -- --no-bundle
pnpm tauri bundle -- --bundles nsis,dmg,appimage

基础配置

src-tauri/tauri.conf.json

json
{
  "productName": "Demo App",
  "version": "0.1.0",
  "identifier": "com.example.demo",
  "build": {
    "beforeDevCommand": "pnpm dev",
    "devUrl": "http://localhost:5173",
    "beforeBuildCommand": "pnpm build",
    "frontendDist": "../dist"
  },
  "bundle": {
    "active": true,
    "targets": "all",
    "icon": [
      "icons/32x32.png",
      "icons/128x128.png",
      "icons/icon.icns",
      "icons/icon.ico"
    ]
  }
}

关键字段:

  • identifier:应用 ID,使用反向域名,发布后不要轻易改。
  • productName:展示名称。
  • version:优先写在 tauri.conf.json;未设置时回退到 Cargo.toml
  • build.frontendDist:前端构建产物目录。
  • bundle.targets:打包目标,或设为 all

额外资源通过 bundle.resources 打进应用资源目录。

Windows

常见目标:nsismsi

Windows 依赖系统 WebView2。可在 bundle.windows.webviewInstallMode 中选择安装方式,例如静默下载 bootstrapper。正式分发需要代码签名。

macOS

常见目标:appdmg

  • dmg 适合直接下载安装。
  • App Store 分发使用独立配置。
  • 正式分发需要代码签名;商店外分发还需要公证。
  • universal-apple-darwin 可同时覆盖 Intel 和 Apple Silicon,体积更大。

Linux

常见目标:AppImagedebrpm

  • AppImage:分发简单,适合通用下载。
  • deb:适合 Debian / Ubuntu 系。
  • rpm:适合 Fedora / RHEL 系。

移动端

Tauri 2 支持 Android 和 iOS:

bash
pnpm tauri android build
pnpm tauri ios build

移动端会把 Rust 编译为库,再交给平台工程打包。发布流程分别走 Google Play 和 App Store。

更新

自动更新使用官方 updater 插件,并在打包时生成更新产物。签名、公证、更新源和 CI 强相关,建议在基础打包稳定后单独维护。

Checklist

  • [ ] 配置 identifierproductNameversion 和图标
  • [ ] 确认 frontendDist 指向前端构建产物
  • [ ] Windows 处理 WebView2 与代码签名
  • [ ] macOS 准备签名和公证
  • [ ] Linux 按分发渠道选择 AppImagedebrpm
  • [ ] 需要热更新时再接入 updater

基于 MIT 许可发布