yzbtdiy

yzbtdiy

github
bilibili

Wails 项目初始化

Wails 是一个可以使用 Go 和 Web 技术编写桌面应用的项目。

安装#

需要有 Go 语言环境,可以从 https://golang.google.cn/ 下载 Go 安装包

Go 安装完成后配置 Go 模块代理可以加速模块下载

go env -w GOPROXY=https://goproxy.cn,direct

使用 go install 可以快速安装 wails 命令行工具

go install github.com/wailsapp/wails/v2/cmd/wails@latest

创建项目#

使用 wails 命令可以快速创建项目,此处使用 vue-ts 模板

-n 项目名称

-t 使用的前端模板

可以从
https://github.com/wailsapp/wails/tree/master/v2/pkg/templates/templates查看所有官方模板

wails init -n wailsapp -t vue-ts

image

环境调整#

正常情况使用默认项目模板开发即可,我个人倾向于使用 Bun 作为 JS/TS 运行时而不是 Nodejs, 所以这里替换一下

npm 替换为 bun#

需要修改两个文件,一个时 wails.json, 一个是 frontend 目录下的 package.json

image

image

将 wails.json 中 npm 对应命令替换为 bun

  "frontend:install": "bun install",
  "frontend:build": "bun run build",
  "frontend:dev:watcher": "bun run dev",

将 frontend 目录下的 package.json 中 scripts 内容替换为使用 bunx 执行 vite 命令

 "scripts": {
    "dev": "bunx --bun vite",
    "build": "bunx --bun vite build",
    "preview": "bunx --bun vite preview"
  }

更新前端依赖#

使用 ncu -u 检查更新,自动修改 package.json 文件,然后使用 bun install 安装即可

image

卸载 typescript 和 vue-tsc

image

一切正常,VSCode 启动

image

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。