Wails:Go 语言挑战 Electron,赌上桌面级应用之未来
원제 · Wails: Golang's Bet On Desktop Grade Apps To Beat Electron
핵심 요약
Wails 凭借无内置浏览器的架构实现了 52 MB 的超小打包体积与优异的运行时录屏性能,但在调用 macOS 原生 API 时因生态尚未成熟而需要借助 Cgo 手写 Objective-C 代码。
하이라이트
Wails 打包体积仅为 52 MB,与 Tauri 的 57 MB 相近,远小于 Electron 的 324 MB。
在冷启动测试中,Electron 以 1890 毫秒领先,Wails 为 2337 毫秒,Tauri 为 2049 毫秒。
热启动表现下 Wails 耗时 395 毫秒,Tauri 为 410 毫秒,Electron 为 350 毫秒。
Wails 运行 wails dev 命令时,Go 端的 API 修改会自动同步生成 TypeScript 类型定义并实时重载应用。
由于 Go 生态缺乏现成的 ScreenCaptureKit 封装,Wails 开发录屏功能需要通过 Cgo 手写约 450 行 Objective-C 原生代码。
타임라인
Wails 的核心架构与技术原理
Wails 的工作运行机制与 Tauri 高度相似,主要区别在于后端采用 Go 语言而非 Rust。前端依然使用 Web 技术栈,通过自动生成的接口调用 Go 管理的原生 API,支持同时编译出 macOS 与 Windows 应用。由于没有内置 Chromium 浏览器,应用体积大幅缩减。
- Wails 结合 Go 后端与 Web 前端渲染构建跨平台桌面应用。
- Wails 放弃内置浏览器,改为复用系统原生的 WebView 渲染引擎。
- 原生 WebView 复用架构显著降低了应用打包产物的体积。
项目结构与类型自动生成机制
应用主入口 main.go 负责配置窗口标题、尺寸、背景色及平台专属选项。前端通过绑定 Go 端 App 结构体暴露出原生函数,在运行 wails dev 开发命令时,Go 端函数的任何改动都会同步更新 API.ts 中的类型声明并触发应用增量重载。
- Wails 的目录结构划分清晰,前端 React 代码集中于 frontend 目录,Go 入口位于 main.go。
- Wails 提供增量编译与热重载,Go 侧代码变更会自动触发 TypeScript 类型文件重构。
体积、启动速度与运行时性能对比
打包体积上 Wails(52 MB)与 Tauri(57 MB)优势巨大,而 Electron 高达 324 MB。冷启动 10 次平均测试中 Electron 耗时 1890 毫秒,Wails 耗时 2337 毫秒,Tauri 耗时 2049 毫秒。但在运行时性能上,Wails 与 Tauri 直连 Mac 原生 API 数据通道,避开了 Electron 从 WebView 抓取画面的 IPC 传输开销。
- Wails 和 Tauri 包体积均在 50-60 MB 左右,仅为 Electron 的六分之一。
- 启动速度方面,Electron 在冷热启动指标上均略微领先 Wails 与 Tauri。
- Wails 直接调用 ScreenCaptureKit,运行时录屏开销显著低于 Electron 的 WebView 截图方案。
开发者体验与底层生态现状
在实现屏幕捕获功能时,Tauri 能够直接引入现成的 Rust crate 库,全流程使用 Rust 开发。Wails 则需要借助 Go 的 Cgo 功能,手动编写约 450 行 Objective-C 原生代码并链接系统的 ScreenCaptureKit 框架。因此,偏好 Go 的开发者可以使用 Wails,但需做好手写底层原生代码的准备。
- Rust 拥有成熟的 screen-capture-kit crate,而 Go 生态缺乏相关封装。
- Wails 开发者需利用 Cgo 机制在 .m 文件中手写 Objective-C 代码来对接 Apple 原生 API。
설명
You already write Go, so why bundle a whole Chromium to ship a desktop app? Wails builds cross-platform desktop apps on the system webview, 52 MB against Electron's 324. The catch is the developer experience: where Tauri leans on Rust crates, Go can leave you hand-writing Objective-C. Worth it if you're choosing a desktop stack. 🔗 Relevant Links https://wails.io https://github.com/wailsapp/wails ❤️ More about us Radically better observability stack: https://betterstack.com/ Written tutorials: https://betterstack.com/community/ Example projects: https://github.com/BetterStackHQ 📱 Socials Twitter: https://twitter.com/betterstackhq Instagram: https://www.instagram.com/betterstackhq/ TikTok: https://www.tiktok.com/@betterstack LinkedIn: https://www.linkedin.com/company/betterstack 📌 Chapters: 0:00 What is Wails? 0:33 How Wails works (Go + native webview) 1:06 Demo: the screen recorder app 1:29 Project structure: main.go and the frontend 1:57 React frontend and auto-generated bindings 2:50 Live reload with wails dev 3:24 Bundle size: Wails vs Tauri vs Electron 4:07 Startup time 4:36 Runtime performance 5:07 Developer experience 5:37 Writing Objective-C with CGo 6:07 Verdict: Wails or Tauri? 6:40 Outro
