前言
通过Go语言的Wails程序,将前端代码编译为桌面应用
准备工作
下载Wails客户端
1
| go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
下载无框架的前端项目模版
其他模版链接可以从官方文档中找到https://wails.io/zh-Hans/docs/community/templates/
-n <product_name>
:指定项目名
-t https://github.com/KiddoV/wails-pure-js-template.git
:指定模版
https://github.com/KiddoV/wails-pure-js-template.git
无框架的模版
1
| wails init -n <product_name> -t https://github.com/KiddoV/wails-pure-js-template.git
|
项目结构
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| + <product_name> + build + bin # 编译后的桌面应用 + darwin # Mac应用编译前的配置 + windows # Windows应用编译前的配置 - appicon.png # 应用程序图标 - README.md + frontend # 在这里存放前端代码 - index.html - app.go - go.mod - main.go - README.md - wails.json
|
打包成桌面应用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| Wails CLI v2.6.0
# Build Options
Platform(s) | darwin/arm64 Compiler | /opt/homebrew/bin/go Skip Bindings | false Build Mode | production Devtools | false Frontend Directory | ~/demo/frontend Obfuscated | false Skip Frontend | false Compress | false Package | true Clean Bin Dir | false LDFlags | Tags | [] Race Detector | false
# Building target: darwin/arm64
• Generating bindings: Done. • No Install command. Skipping. • No Build command. Skipping. • Compiling application: Done. • Packaging application: Done. Built '~/<product_name>/build/bin/<product_name>.app/Contents/MacOS/<product_name>' in 1m2.34s.
♥ If Wails is useful to you or your company, please consider sponsoring the project:
|
完成
参考文献
Wails官方文档