Files

124 lines
3.1 KiB
Plaintext
Raw Permalink Normal View History

2022-08-27 20:17:15 +10:00
---
sidebar_position: 10
---
# Hello World
2023-12-09 16:32:29 +11:00
The aim of this tutorial is to get you up and running with the most basic application using Wails. You will be able to:
2022-08-27 20:17:15 +10:00
- Create a new Wails application
- Build the application
- Run the application
:::note
2022-09-18 11:00:39 +10:00
2023-12-09 16:32:29 +11:00
This tutorial uses Windows as the target platform. Output will vary slightly depending on your operating system.
2022-09-18 11:00:39 +10:00
2022-08-27 20:17:15 +10:00
:::
## Create a new Wails application
2023-12-09 16:32:29 +11:00
To create a new Wails application using the default vanilla JS template, you need to run the following command:
2022-08-27 20:17:15 +10:00
```bash
wails init -n helloworld
```
You should see something similar to the following:
```
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.
```
2023-12-09 16:32:29 +11:00
This will create a new directory called `helloworld` in the current directory. In this directory, you will find a number of files:
2022-08-27 20:17:15 +10:00
```
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
```
## Build the application
To build the application, change to the new `helloworld` project directory and run the following command:
```bash
wails build
```
You should see something like the following:
```
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
2023-12-09 16:32:29 +11:00
Devtools: false
2022-08-27 20:17:15 +10:00
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.
```
This has compiled the application and saved it in the `build/bin` directory.
## Run the application
If we view the `build/bin` directory in Windows Explorer, we should see our project binary:
2022-09-18 11:00:39 +10:00
```mdx-code-block
2022-08-27 20:17:15 +10:00
<div class="text--center">
<img
2022-08-29 20:04:52 +10:00
src={require("@site/static/img/helloworld-app-icon.webp").default}
2022-08-27 20:17:15 +10:00
width="134px"
/>
</div>
<br />
2022-09-18 11:00:39 +10:00
```
2022-08-27 20:17:15 +10:00
We can run it by simply double-clicking the `helloworld.exe` file.
On Mac, Wails generates a `helloworld.app` file which can be run by double-clicking it.
On Linux, you can run the application using `./helloworld` from the `build/bin` directory.
You should see the application working as expected:
2022-09-18 11:00:39 +10:00
```mdx-code-block
2022-08-27 20:17:15 +10:00
<div class="text--center">
<img
2022-08-29 20:04:52 +10:00
src={require("@site/static/img/windows-default-app.webp").default}
2022-08-27 20:17:15 +10:00
width="50%"
className="screenshot"
/>
</div>
<br />
2022-09-18 11:00:39 +10:00
```