Files
image-workbench-desktop/DESKTOP_BUILD.md
T

3.2 KiB
Raw Blame History

构建与打包(桌面版)

一、依赖

项 版本 说明
Node.js ≥ 20 前端构建(esbuild 逐文件压缩 + 拼接)
Rust ≥ 1.90 Tauri 后端;macOS 用默认 toolchain,Windows 必须 MSVC
Xcode CLT — 仅 macOS:xcode-select --install
VS Build Tools 2019/2022 + 「使用 C++ 的桌面开发」 仅 Windows
WebView2 Runtime — Windows 10 需安装;Win11 自带

二、日常命令

npm ci                 # 首次
npm run build          # 只出前端 dist/(含运行时插件)
npm run app:dev        # 开发(启动前自动 build,改完源码需手动再 build)
npm run app:build      # 打包当前平台(mac:.app + .dmg;Win:.exe + .msi)

首次 app:build 要编译 ~250 个 Rust crate,约 2–5 分钟;之后增量很快。

本机(沙箱)里 cargo/npm 的缓存目录被限制在仓库内,所以 build 时用 CARGO_HOME=$PWD/.cargo-home npm_config_cache=$PWD/.npm-cache; 在你自己的机器上不需要,直接用默认缓存即可。

三、产物位置

平台 路径
macOS src-tauri/target/release/bundle/macos/image-workbench.app
macOS dmg src-tauri/target/release/bundle/dmg/image-workbench_3.24.85_*.dmg
Windows msi src-tauri/target/release/bundle/msi/*.msi
Windows exe(setup) src-tauri/target/release/bundle/nsis/*-setup.exe

四、Windows 打包(只能在 Windows 上做)

Tauri 不支持从 macOS 交叉编译 Windows 产物,必须在 Windows 机器上跑:

# 1) 一次性环境(有 winget 的话)
winget install OpenJS.NodeJS.LTS
winget install Rustlang.Rustup
winget install Microsoft.VisualStudio.2022.BuildTools --override "--quiet --add Microsoft.VisualStudio.Workload.VCTools"
winget install Microsoft.EdgeWebView2Runtime

# 2) 确认 Rust 走的是 MSVC
rustup default stable-msvc
rustc -V

# 3) 构建
git clone <本仓库地址> image-workbench-desktop
cd image-workbench-desktop
npm ci
npm run app:build

产物在 src-tauri\target\release\bundle\ 下的 msi\ 与 nsis 目录。

常见坑:

  • link.exe not found → VS Build Tools 没装「使用 C++ 的桌面开发」工作负载
  • 中文路径 / 空格路径可能让 NSIS 失败 → 仓库放在 C:\work\ 这类纯英文路径
  • 没签名 → SmartScreen 会提示「未知发布者」,点「更多信息 → 仍要运行」

五、签名与分发(本次不做)

macOS 未签名:首次打开要 右键 → 打开(或在「系统设置 → 隐私与安全性」里放行)。 Windows 未签名:SmartScreen 提示,仅影响首次运行体验。 要正式分发再考虑 Apple Developer ID / Windows 代码签名证书,与本次迁移无关。

六、插件资源的来路

网页版插件由 Cloudflare KV 在 /plugins/* 提供;桌面版没有服务端,所以把 发布产物(plugins/runtime/*.js,文件名带内容哈希)随仓库带走,构建后由 scripts/copy-plugins.js 拷进 dist/plugins/。每个文件的 SHA-256 与 plugins/index.json 里的 integrity 一致(已校验)。

升级插件时:换掉 plugins/runtime/ 里的文件 + 同步 plugins/index.json 即可,代码不用动。