mirror of
https://github.com/wavetermdev/wails.git
synced 2026-08-05 13:53:43 -07:00
124 lines
3.0 KiB
Plaintext
124 lines
3.0 KiB
Plaintext
---
|
|
sidebar_position: 10
|
|
---
|
|
|
|
# 你好世界
|
|
|
|
本教程的目的是让您使用 Wails 启动并运行最基本的应用程序。 你将可以:
|
|
|
|
- 创建一个新的 Wails 应用
|
|
- 构建应用
|
|
- 运行应用
|
|
|
|
:::note
|
|
|
|
本教程使用 Windows 作为目标平台。 根据您的操作系统,输出会略有不同。
|
|
|
|
:::
|
|
|
|
## 创建一个新的 Wails 应用
|
|
|
|
使用默认的 vanilla JS 模板创建新的 Wails 程序, 您需要运行这个指令:
|
|
|
|
```bash
|
|
wails init -n helloworld
|
|
```
|
|
|
|
您应该会看到如下输出:
|
|
|
|
```
|
|
Wails CLI v2.0.0
|
|
|
|
Initialising Project 'helloworld'
|
|
---------------------------------
|
|
|
|
Project Name: helloworld
|
|
Project Directory: C:\Users\leaan\tutorial\helloworld
|
|
Project Template: vanilla
|
|
Template Support: https://wails.io
|
|
|
|
Initialised project 'helloworld' in 232ms.
|
|
```
|
|
|
|
这将在当前目录中创建一个名为 `helloworld` 的新目录。 在此目录中,您将找到许多文件:
|
|
|
|
```
|
|
build/ - Contains the build files + compiled application
|
|
frontend/ - Contains the frontend files
|
|
app.go - Contains the application code
|
|
main.go - The main program with the application configuration
|
|
wails.json - The project configuration file
|
|
go.mod - The go module file
|
|
go.sum - The go module checksum file
|
|
```
|
|
|
|
## 构建应用
|
|
|
|
要构建应用程序,请切换到新的 `helloword` 项目目录并运行以下命令:
|
|
|
|
```bash
|
|
wails build
|
|
```
|
|
|
|
您应该会看到如下输出:
|
|
|
|
```
|
|
Wails CLI v2.0.0
|
|
|
|
App Type: desktop
|
|
Platforms: windows/amd64
|
|
Compiler: C:\Users\leaan\go\go1.18.3\bin\go.exe
|
|
Build Mode: Production
|
|
Devtools: false
|
|
Skip Frontend: false
|
|
Compress: false
|
|
Package: true
|
|
Clean Build Dir: false
|
|
LDFlags: ""
|
|
Tags: []
|
|
Race Detector: false
|
|
|
|
Building target: windows/amd64
|
|
------------------------------
|
|
- Installing frontend dependencies: Done.
|
|
- Compiling frontend: Done.
|
|
- Generating bundle assets: Done.
|
|
- Compiling application: Done.
|
|
Built 'C:\Users\leaan\tutorial\helloworld\build\bin\helloworld.exe' in 10.616s.
|
|
```
|
|
|
|
这已经编译了应用程序并将其保存在 `build/bin` 目录中。
|
|
|
|
## 运行应用
|
|
|
|
如果我们在 Windows 文件管理器中查看 `build/bin` 目录,我们应该看到我们的项目二进制文件:
|
|
|
|
```mdx-code-block
|
|
<div class="text--center">
|
|
<img
|
|
src={require("@site/static/img/helloworld-app-icon.webp").default}
|
|
width="134px"
|
|
/>
|
|
</div>
|
|
<br />
|
|
```
|
|
|
|
我们可以通过简单的双击 `helloworld.exe` 文件来运行它。
|
|
|
|
在 Mac 上,Wails 生成一个 `helloworld.app` 文件,可以通过双击来运行。
|
|
|
|
在 Linux 上,您可以从 `build/bin` 目录使用 `./helloword` 运行应用程序。
|
|
|
|
您应该看到应用程序正常工作:
|
|
|
|
```mdx-code-block
|
|
<div class="text--center">
|
|
<img
|
|
src={require("@site/static/img/windows-default-app.webp").default}
|
|
width="50%"
|
|
className="screenshot"
|
|
/>
|
|
</div>
|
|
<br />
|
|
```
|