概要
以下、自分用のメモです。なんか面白そうなので、ちょっと使い方とかメモしようと思いました。
WailsというGoでクロスプラットフォームなGUIアプリを開発できるライブラリみたいですね。
以前から存在していたみたいで、そちらはV1として現在機能がフリーズされている模様です。
新たにV2が出ているので、本ブログではV2で遊んでいこうと思っています。
V1はElectronベースだったみたいですが、V2からOSネイティブのレンダリングエンジンを利用するようになっているみたい。
なので、ブラウザが埋め込まれないパターンですね。
まだ、インストールくらいしか出来ていないので、今回はそれのメモです。
インストール
以下の手順をやっただけです。環境はWindowsで試しました。
UPX のインストール
オプショナルでUPXを使うみたいなので、ついでにインストール。
Scoop でインストールしました。
scoop install upx
Wails のインストール
go install github.com/wailsapp/wails/v2/cmd/wails@latest
確認
flutter の様に doctor サブコマンドがついているみたいなので、実行。
> wails doctor Wails CLI v2.1.0 Scanning system - Please wait (this may take a long time)...Done. System ------ Go Version: go1.19.2 Platform: windows Architecture: amd64 Wails ------ Version: v2.1.0 Dependency Package Name Status Version ---------- ------------ ------ ------- WebView2 N/A Installed 106.0.1370.52 npm N/A Installed 8.19.2 *upx N/A Installed upx 3.96 *nsis N/A Available * - Optional Dependency Diagnosis --------- Your system is ready for Wails development! Optional package(s) installation details: - nsis : Available at https://nsis.sourceforge.io/Download If Wails is useful to you or your company, please consider sponsoring the project: https://github.com/sponsors/leaanthony
オッケイみたいですね。
試してみる
wails init
でテンプレプロジェクトを出力してくれるみたい。 UI側はSvelteにしておきました。
> wails init -n app1 -t svelte Wails CLI v2.1.0 Initialising Project 'app1' --------------------------- Project Name: app1 Project Directory: C:\Users\xxxxx\wailsapp\app1 Project Template: svelte Template Support: https://wails.io Initialised project 'app1' in 9.019s. If Wails is useful to you or your company, please consider sponsoring the project: https://github.com/sponsors/leaanthony
出来たみたい。では、中にはいって起動してみます。
> cd app1 > wails dev Wails CLI v2.1.0 Executing: go mod tidy - Generating bindings: Done. - Installing frontend dependencies: Done. - Compiling frontend: Done. > frontend@0.0.0 dev > vite VITE v3.1.8 ready in 727 ms Vite Server URL: http://127.0.0.1:5173/ ➜ Local: http://127.0.0.1:5173/ Running frontend DevWatcher command: 'npm run dev' ➜ Network: use --host to expose Building application for development... - Generating bindings: Done. - Generating bundle assets: Done. - Compiling application: Done. INF | Serving assets from frontend DevServer URL: http://127.0.0.1:5173/ DEB | WebView2 Runtime Version '106.0.1370.52' installed. Minimum version required: 94.0.992.31. DEB | [DevWebServer] Serving DevServer at http://localhost:34115
npmで大量にライブラリを落としているせいなのか、OSがWindowsだからなのか分かりませんが、めっちゃ時間かかります・・・数分くらい。
しばらくすると、以下のようなアプリが起動してくれます。
一旦、今回はここまで。
参考情報
過去の記事については、以下のページからご参照下さい。
サンプルコードは、以下の場所で公開しています。