docs: document wails binding generation
This commit is contained in:
@@ -125,6 +125,48 @@ Windows build 资源:
|
||||
|
||||
`wails3 build` 会重新生成 `frontend/bindings`,当前 CLI 生成的是 `.js` bindings。
|
||||
|
||||
## Wails Bindings 生成流程
|
||||
|
||||
版本要求:
|
||||
|
||||
- Go:`1.23.0`
|
||||
- Wails CLI:`wails3 v3.0.0-alpha.9`
|
||||
- 前端 runtime:`@wailsio/runtime 3.0.0-alpha.66`
|
||||
|
||||
需要重新生成 bindings 的情况:
|
||||
|
||||
- 新增、删除或改名 Wails 服务。
|
||||
- 修改 Go 服务的公开方法签名。
|
||||
- 修改前端需要使用的请求模型、返回模型或 JSON 字段。
|
||||
- 在 `main.go` 的 `Services` 列表注册新服务。
|
||||
|
||||
从项目根目录执行:
|
||||
|
||||
```powershell
|
||||
$env:Path += ";$(go env GOPATH)\bin"
|
||||
wails3 generate bindings -clean=true
|
||||
```
|
||||
|
||||
生成结果位于 `frontend/bindings/`。当前 Wails v3 alpha CLI 生成 `.js` 文件,前端源码使用无扩展名 import,例如:
|
||||
|
||||
```ts
|
||||
import { ListTasks } from '../../../bindings/cmbone/internal/services/imageoptimizationservice'
|
||||
```
|
||||
|
||||
失败处理:
|
||||
|
||||
- `wails3` 找不到:确认已安装固定版本,并把 `$(go env GOPATH)\bin` 加入当前 PowerShell PATH。
|
||||
- 版本不匹配:不要用 `latest`,重新安装 `github.com/wailsapp/wails/v3/cmd/wails3@v3.0.0-alpha.9`。
|
||||
- Go 编译错误:先运行 `go test ./...` 或 `go build -o bin\cmbone.exe .`,修复服务或模型错误后再生成。
|
||||
- 前端类型或 import 错误:重新执行 `wails3 generate bindings -clean=true`,再运行 `cd frontend && npm run build`。
|
||||
- 本机暂时无法生成:只允许按已有 binding 模式做最小手工修正,并在 `progress.md` 写清原因、范围和后续补救。
|
||||
|
||||
提交要求:
|
||||
|
||||
- 服务或模型变更必须和对应 `frontend/bindings` 变更同一个 task 提交。
|
||||
- 提交前至少运行 `go test ./...`、`cd frontend && npm run build`。
|
||||
- 涉及完整启动或打包链路时,再运行 `go build -o bin\cmbone.exe .` 或 `cmd /c build.bat`。
|
||||
|
||||
## 版本升级规则
|
||||
|
||||
- 升级 Go 前,先确认 Wails v3 alpha、SQLite 和热键库的兼容性。
|
||||
|
||||
Reference in New Issue
Block a user