メインコンテンツにスキップ
バージョン: v2.8.0

Hello World

このチュートリアルの目的は、Wailsを使用して、最も基礎的なアプリケーションを起動および実行することです。 あなたは、次のことができるようになります:

  • 新しいWailsアプリケーションを作成する
  • アプリケーションをビルドする
  • アプリケーションを実行する
備考

このチュートリアルでは、Windowsをターゲットプラットフォームとして使用します。 出力される内容は、オペレーティングシステムによって多少異なります。

新しいWailsアプリケーションを作成する

デフォルトのバニラJSテンプレートを使用して、新しいWailsアプリケーションを作成するには、次のコマンドを実行します:

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プロジェクトディレクトリに移動し、次のコマンドを実行します:

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ディレクトリを閲覧すると、プロジェクトのバイナリファイルが存在するはずです:


helloworld.exeファイルをダブルクリックするだけで起動できます。

Macの場合、Wailsはhelloworld.appファイルを生成します。このファイルをダブルクリックすることで起動できます。

Linuxの場合、build/binディレクトリ内の./helloworldを呼び出すことでアプリケーションを起動できます。

アプリケーションが期待したとおりに動作することでしょう: