命令行
Wails CLI 有许多用于管理项目的命令。 所有命令都以此方式运行:
wails <命令> <标志>
初始化
wails init 用于生成项目。
| 标志 | 描述 | 默认 |
|---|---|---|
| -n "项目名称" | 项目名称。 强制必填 | |
| -d "项目目录" | 要创建的项目目录 | 项目名 |
| -g | 初始化 git 存储库 | |
| -l | 可用项目模板列表 | |
| -q | 禁止输出到控制台 | |
| -t "模板名称" | 要使用的项目模板。 这可能是默认模板的名称或托管在 github 上的远程模板的 URL 。 | vanilla |
| -ide | Generate IDE project files vscode or goland | |
| -f | 强制构建应用 | false |
示例: wails init -n test -d mytestproject -g -ide vscode -q
这将在 "mytestproject" 目录生成一个名为 "test" 的项目,初始化 git,生成 vscode 项目文件并静默执行。
可以在 此处 找到有关在 Wails 中使用 IDE 的更多信息。
远程模板
支持远程模板(托管在 GitHub )并且可以使用模板项目的 URL 进行安装。
示例: wails init -n test -t https://github.com/leaanthony/testtemplate[@v1.0.0]
可以在 此处 找到社区维护的模板列表
Wails 项目不维护也不对第 3 方模板负责
如果您不确定某个模板,请检查 package.json 和 wails.json 中安装的模块和运行的脚本。
构建
wails build 用于将您的项目编译为生产可用的二进制文件。
| 标志 | 描述 | 默认 |
|---|---|---|
| -clean | 清理 build/bin 目录 | |
| -compiler "编译器" | 使用不同的 go 编译器来构建,例如 go1.15beta1 | go |
| -debug | Retains debug information in the application and shows the debug console. 允许在应用程序窗口中使用 devtools | |
| -devtools | Allows the use of the devtools in the application window in production (when -debug is not used). Ctrl/Cmd+Shift+F12 may be used to open the devtools window. NOTE: This option will make your application FAIL Mac appstore guidelines. Use for debugging only. | |
| -dryrun | 打印构建命令但不执行它 | |
| -f | 强制构建应用 | |
| -garbleargs | 传递给 garble 的参数 | -literals -tiny -seed=random |
| -ldflags "标志" | 传递给编译器的额外 ldflags | |
| -m | 编译前跳过 mod tidy | |
| -nopackage | 不打包应用程序 | |
| -nocolour | 在输出中禁用颜色 | |
| -nosyncgomod | 不同步 go.mod 中的 Wails 版本 | |
| -nsis | 为 Windows 生成 NSIS 安装程序 | |
| -o 文件名 | 输出文件名 | |
| -obfuscated | 使用 garble 混淆应用程序 | |
| -platform | 为指定的 平台(逗号分割)构建,例如: windows/arm64。 windows/arm64。 注意,如果不给出架构,则使用 runtime.GOARCH。 | platform = GOOS environment variable if given else runtime.GOOS.arch = GOARCH environment variable if given else runtime.GOARCH. |
| -race | 使用 Go 的竞态检测器构建 | |
| -s | 跳过前端构建 | |
| -skipbindings | 跳过 bindings 生成 | |
| -tags "额外标签" | 构建标签以传递给 Go 编译器。 必须引用。 空格或逗号(但不能同时使用)分隔 | |
| -trimpath | 从生成的可执行文件中删除所有文件系统路径。 | |
| -u | 更新项目的 go.mod 以使用与 CLI 相同版本的 Wails | |
| -upx | 使用 “upx” 压缩最终二进制文件 | |
| -upxflags | 传递给 upx 的标志 | |
| -v int | 详细级别 (0 - silent, 1 - default, 2 - verbose) | 1 |
| -webview2 | WebView2 安装策略:download,embed,browser,error. | download |
| -windowsconsole | 保留Windows构建控制台窗口 |
有关 webview2 标志的详细描述,请参阅 Windows 系统指南。
如果您更喜欢使用标准 Go 工具进行构建,请参阅 手动构建指南。
示例:
wails build -clean -o myproject.exe
在 Mac 上,应用程序将被绑定到 Info.plist,而不是 Info.dev.plist。
在苹果芯片上使用 UPX 相关的 问题。
You can override default minimal version of macOS for your app by providing version via CGO_CFLAGS and CGO_LDFLAGS environment variables. e.g. CGO_CFLAGS=-mmacosx-version-min=10.15.0 CGO_LDFLAGS=-mmacosx-version-min=10.15.0 wails build
一些防病毒软件供应商误将 upx 压缩的二进制文件标记为病毒,请查看相关 问题。
平台
支持的平台有:
| 平台 | 描述 |
|---|---|
| darwin | MacOS + architecture of build machine |
| darwin/amd64 | MacOS 10.13+ AMD64 |
| darwin/arm64 | MacOS 11.0+ ARM64 |
| darwin/universal | MacOS AMD64+ARM64 universal application |
| windows | Windows 10/11 + architecture of build machine |
| windows/amd64 | Windows 10/11 AMD64 |
| windows/arm64 | Windows 10/11 ARM64 |
| linux | Linux + architecture of build machine |
| linux/amd64 | Linux AMD64 |
| linux/arm64 | Linux ARM64 |
诊断检查
wails doctor 将运行诊断程序以确保您的系统已准备好进行开发。
示例:
Wails CLI v2.0.0-beta
Scanning system - Please wait (this may take a long time)...Done.
System
------
OS: Windows 10 Pro
Version: 2009 (Build: 19043)
ID: 21H1
Go Version: go1.18
Platform: windows
Architecture: amd64
Dependency Package Name Status Version
---------- ------------ ------ -------
WebView2 N/A Installed 93.0.961.52
npm N/A Installed 6.14.15
*upx N/A Installed upx 3.96
* - Optional Dependency
Diagnosis
---------
Your system is ready for Wails development!