mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 13:22:55 +08:00
123 lines
3.9 KiB
Plaintext
123 lines
3.9 KiB
Plaintext
---
|
||
sidebar_position: 10
|
||
---
|
||
|
||
# Hello World
|
||
|
||
Цель этого урока — запустить наиболее базовое приложение, использующее Wails. Вы сможете:
|
||
|
||
- Создавать новое Wails приложение
|
||
- Собирать приложение
|
||
- Запускать приложение
|
||
|
||
:::note
|
||
|
||
В этом уроке в качестве целевой платформы используется Windows. Вывод будет варьироваться в зависимости от вашей операционной системы.
|
||
|
||
:::
|
||
|
||
## Создаем новое Wails приложение
|
||
|
||
Чтобы создать новое Wails приложение, использующее стандартный шаблон JS, вам нужно выполнить следующую команду:
|
||
|
||
```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
|
||
```
|
||
|
||
## Сборка приложения
|
||
|
||
Чтобы собрать приложение, перейдите в новую директорию `helloworld` и запустите следующую команду:
|
||
|
||
```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
|
||
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`.
|
||
|
||
## Запуск приложения
|
||
|
||
Если мы откроем папку `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 вы можете запустить приложение с помощью файла `./helloworld` из папки `build/bin`.
|
||
|
||
Вы должны видеть приложение, работающее так, как ожидалось:
|
||
|
||
```mdx-code-block
|
||
<div class="text--center">
|
||
<img
|
||
src={require("@site/static/img/windows-default-app.webp").default}
|
||
width="50%"
|
||
className="screenshot"
|
||
/>
|
||
</div>
|
||
<br />
|
||
```
|