Files
2026-04-10 13:49:04 +08:00

120 lines
2.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 打包构建指南
本项目基于 **Wails v2** 框架,使用 Go + React 构建桌面应用。
---
## 前置条件
确保以下工具已安装:
| 工具 | 验证命令 | 安装方式 |
|------|---------|---------|
| Go | `go version` | [golang.org](https://golang.org/dl/) |
| Node.js & npm | `npm -v` | [nodejs.org](https://nodejs.org/) |
| Wails CLI | `wails version` | `go install github.com/wailsapp/wails/v2/cmd/wails@latest` |
> **注意:** 如果终端提示 `command not found`,需要确保 PATH 中包含以下路径:
> ```bash
> export PATH="/usr/local/go/bin:$(go env GOPATH)/bin:/opt/homebrew/bin:$PATH"
> ```
> 建议将此行加入 `~/.zshrc` 中。
---
## 基本打包(当前平台)
```bash
wails build
```
构建产物位于 `build/bin/` 目录下:
- **macOS**: `build/bin/Betting-Assistant.app`(可直接双击运行的 .app 包)
---
## 常用构建选项
```bash
# 生产模式打包(默认)
wails build
# 打包并开启压缩(减小体积,使用 UPX)
wails build -upx
# 打包时去除调试信息(进一步减小体积)
wails build -ldflags="-s -w"
# 保留 DevTools(方便调试)
wails build -devtools
# 代码混淆
wails build -obfuscated
# 跳过前端构建(前端未改动时加速打包)
wails build -skipfrontend
# 清空 bin 目录后再构建
wails build -clean
```
---
## 跨平台构建
Wails v2 **不支持直接交叉编译**,需要在目标平台上构建。
| 平台 | 构建命令 | 产物 |
|------|---------|------|
| macOS (ARM) | `wails build -platform darwin/arm64` | `.app` |
| macOS (Intel) | `wails build -platform darwin/amd64` | `.app` |
| Windows | `wails build -platform windows/amd64` | `.exe` |
| Linux | `wails build -platform linux/amd64` | 二进制文件 |
> Windows 和 Linux 的交叉编译需要额外的工具链配置,建议在对应系统上直接构建。
---
## 自定义应用图标
替换 `build/appicon.png` 为你的图标文件(推荐 1024x1024 PNG),然后重新构建。
---
## 一键构建脚本
可以在项目根目录创建脚本 `build.sh`
```bash
#!/bin/bash
export PATH="/usr/local/go/bin:$(go env GOPATH)/bin:/opt/homebrew/bin:$PATH"
wails build -clean -ldflags="-s -w"
echo "✅ 构建完成: build/bin/"
ls -la build/bin/
```
赋予执行权限后使用:
```bash
chmod +x build.sh
./build.sh
```
---
## 常见问题
### Q: `wails: command not found`
```bash
go install github.com/wailsapp/wails/v2/cmd/wails@latest
```
### Q: `npm: executable file not found in $PATH`
确保 `/opt/homebrew/bin` 在 PATH 中(Homebrew 安装的 Node.js)。
### Q: 检查构建环境是否就绪
```bash
wails doctor
```
此命令会检查所有依赖并给出修复建议。