Files

124 lines
3.8 KiB
Plaintext
Raw Permalink Normal View History

2022-08-09 20:48:29 +10:00
---
sidebar_position: 10
---
# Hello World
2023-03-11 17:57:56 +11:00
このチュートリアルの目的は、Wailsを使用して、最も基礎的なアプリケーションを起動および実行することです。 あなたは、次のことができるようになります:
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
- 新しいWailsアプリケーションを作成する
- アプリケーションをビルドする
- アプリケーションを実行する
2022-08-09 20:48:29 +10:00
:::note
2022-09-18 11:00:39 +10:00
2023-03-11 17:57:56 +11:00
このチュートリアルでは、Windowsをターゲットプラットフォームとして使用します。 出力される内容は、オペレーティングシステムによって多少異なります。
2022-09-18 11:00:39 +10:00
2022-08-09 20:48:29 +10:00
:::
2023-03-11 17:57:56 +11:00
## 新しいWailsアプリケーションを作成する
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
デフォルトのバニラJSテンプレートを使用して、新しいWailsアプリケーションを作成するには、次のコマンドを実行します:
2022-08-09 20:48:29 +10:00
```bash
wails init -n helloworld
```
2023-03-11 17:57:56 +11:00
すると、次のように表示されます:
2022-08-09 20:48:29 +10:00
```
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-03-11 17:57:56 +11:00
これにより、カレントディレクトリに`helloworld`という新しいディレクトリが作成されます。 このディレクトリには、いくつかのファイルがあります:
2022-08-09 20:48:29 +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
```
2023-03-11 17:57:56 +11:00
## アプリケーションをビルドする
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
アプリケーションをビルドするには、新しくできた`helloworld`プロジェクトディレクトリに移動し、次のコマンドを実行します:
2022-08-09 20:48:29 +10:00
```bash
wails build
```
2023-03-11 17:57:56 +11:00
すると、次のように表示されます:
2022-08-09 20:48:29 +10:00
```
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-09-08 23:25:21 +10:00
Devtools: false
2022-08-09 20:48:29 +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.
```
2023-03-11 17:57:56 +11:00
これにより、アプリケーションがコンパイルされ、`build/bin`ディレクトリに保存されます。
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
## アプリケーションを実行する
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
Windowsのエクスプローラで`build/bin`ディレクトリを閲覧すると、プロジェクトのバイナリファイルが存在するはずです:
2022-08-09 20:48:29 +10:00
2022-09-18 11:00:39 +10:00
```mdx-code-block
2022-08-09 20:48:29 +10:00
<div class="text--center">
2022-08-27 20:17:15 +10:00
<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"
/>
2022-08-09 20:48:29 +10:00
</div>
2022-08-27 20:17:15 +10:00
<br />
2022-09-18 11:00:39 +10:00
```
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
`helloworld.exe`ファイルをダブルクリックするだけで起動できます。
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
Macの場合、Wailsは`helloworld.app`ファイルを生成します。このファイルをダブルクリックすることで起動できます。
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
Linuxの場合、`build/bin`ディレクトリ内の`./helloworld`を呼び出すことでアプリケーションを起動できます。
2022-08-09 20:48:29 +10:00
2023-03-11 17:57:56 +11:00
アプリケーションが期待したとおりに動作することでしょう:
2022-08-09 20:48:29 +10:00
2022-09-18 11:00:39 +10:00
```mdx-code-block
2022-08-09 20:48:29 +10:00
<div class="text--center">
2022-08-27 20:17:15 +10:00
<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"
/>
2022-08-09 20:48:29 +10:00
</div>
2022-08-27 20:17:15 +10:00
<br />
2023-03-11 17:57:56 +11:00
```