基本的には下記の公式マニュアルに沿って環境構築を進めれば良い
ここでは, ぼくが実際に進めた手順を記載しておく
Tauri のマニュアルセットアップ を参考にフロントエンドのプロジェクト雛形を構築する
npx create-next-app@latest tauri-app
✔ Would you like to use TypeScript? … No / Yes
✔ Would you like to use ESLint? … No / Yes
✔ Would you like to use Tailwind CSS? … No / Yes
✔ Would you like your code inside a `src/` directory? … No / Yes
✔ Would you like to use App Router? (recommended) … No / Yes
✔ Would you like to use Turbopack for `next dev`? … No / Yes
✔ Would you like to customize the import alias (`@/*` by default)? … No / Yes
✔ What import alias would you like configured? … @/*cd tauri-app
yarn add -D @tauri-apps/cli@latestyarn tauri init
yarn run v1.22.22
✔ What is your app name? · tauri-app
✔ What should the window title be? · tauri-app
✔ Where are your web assets (HTML/CSS/JS) located, relative to the "<current dir>/src-tauri/tauri.conf.json" file that will be created? · ..
✔ What is the url of your dev server? · http://localhost:3000
✔ What is your frontend dev command? · yarn dev
✔ What is your frontend build command? · yarn build下記を参考に ./tauri-app/package.json の script に tauri コマンドを追加
til-tauri/tauri-app/package.json
Line 10 in 28fbc69
下記を参考に ./tauri-app/next.config.ts を修正
til-tauri/tauri-app/next.config.ts
Lines 1 to 14 in 28fbc69
ビルド可能であることを確認
yarn buildexport CC=clang && yarn tauri devApple Silicon の場合, export CC=clang を指定しなければビルドに失敗してしまう
iOS 開発ができるように下記コマンドを実行して初期化する
# `./tauri-app/` で実行
yarn tauri ios init起動確認する
yarn tauri ios devシミュレータがダウンロードされていない場合は, コマンド実行中にダウンロードが始まってしまうので, 先に済ませておいた方が良い
シミュレータが起動した後も Tauri のバンドルが時間がかかる(体感10分くらい待った)ので, シミュレータ起動後何も動いていないように感じても気長に待つ必要がある
# `./tauri-app/` で実行
yarn tauri android init起動確認する
yarn tauri android devシミュレータがダウンロードされていない場合は, エラーになってしまうので, 先に済ませておく Tauri の対応 Java バージョンが 17 なので, ビルド時に Java17 が指定されていないとエラーになってしまう
基本的には下記の Next.js 公式ドキュメントを参考に進める
# `./tauri-app/` で実行
yarn add -D vitest @vitejs/plugin-react jsdom @testing-library/react @testing-library/dom vite-tsconfig-paths./tauri-app/vitest.config.mts を作成する
til-tauri/tauri-app/vitest.config.mts
Lines 1 to 13 in d17b12a
下記を参考に ./tauri-app/package.json の script に test:front コマンドを追加
til-tauri/tauri-app/package.json
Line 12 in d17b12a
下記コマンドでテストを実行する
yarn test:frontフロントエンドテストで IPC(Inter-Process Communication) をモック化したい場合
# `./tauri-app/` で実行
yarn add -D @tauri-apps/api @testing-library/user-event下記のように mockIPC を用いて IPC(Inter-Process Communication) をモック化することができる
til-tauri/tauri-app/src/components/sample-components.test.tsx
Lines 13 to 17 in 46c48e0
Cargo には標準でテスト機構が含まれているため, 特別な環境構築は不要
下記コマンドでテストを実行する
# `./tauri-app/src-tauri/` で実行
cargo test下記を参考に ./tauri-app/package.json の script に test コマンドにフロントエンドテストとバックエンドテストをまとめる
til-tauri/tauri-app/package.json
Line 11 in 51f492f
下記コマンドでテストを実行する
# `./tauri-app/` で実行
yarn testフロントエンドとバックエンドのテストもそれぞれ分けて実行できるように, 下記を参考に ./tauri-app/package.json の script に test:front コマンドと test:back コマンドをそれぞれ作成
til-tauri/tauri-app/package.json
Lines 12 to 13 in 51f492f
基本的には下記の Playright 公式ドキュメントを参考に進める
下記のコマンドで Playwright をインストールする
# `./tauri-app/` で実行
yarn create playwright
# ...(中略)
✔ Where to put your end-to-end tests? · e2e
✔ Add a GitHub Actions workflow? (y/N) · false
✔ Install Playwright browsers (can be done manually via 'yarn playwright install')? (Y/n) · true自動生成される ./tests-examples/demo-todo-app.spec.ts は削除してしまっても構わない
下記を参考に ./playwright.config.ts を編集
- レポートの出力先を
./playwright-reportに指定し, ブラウザを起動しないように設定するtil-tauri/tauri-app/playwright.config.ts
Line 25 in 6274a4c
- モバイル向けテストエージェントを活性化(コメントアウトを外す)する
til-tauri/tauri-app/playwright.config.ts
Lines 52 to 60 in 6274a4c
下記を参考に vitest のテスト対象から ./e2e/ 配下を外す
til-tauri/tauri-app/vitest.config.mts
Line 9 in 24def96
下記を参考に ./tauri-app/package.json の script に e2e コマンドを追加
til-tauri/tauri-app/package.json
Line 14 in 791877e
下記コマンドでテストを実行する
# `./tauri-app/` で実行
yarn e2e基本的に下記の Storybook 公式ドキュメントを参考に進める
下記のコマンドで Storybook をインストールする
# `./tauri-app/` で実行
yarn create storybook
# ...(中略)
What do you want to use Storybook for? # そのまま Enter
# ...(中略)
Do you want to migrate? … yes自動生成される ./src/stories は不要なので削除
下記を参考に自動生成される ./.storybook/main.ts を修正
下記を参考に自動生成される ./.storybook/preview.ts を修正
下記を参考に ./postcss.config.mjs を修正
til-tauri/tauri-app/postcss.config.mjs
Lines 2 to 4 in 86600f5
下記コマンドで Storybook を起動する
# `./tauri-app/` で実行
yarn storybook基本的には下記の Next.js 公式ドキュメントを参考に進める
# `./tauri-app/` で実行
yarn add -D prettier eslint-config-prettier下記を参考に ./tauri-app/package.json の script に format コマンドを追加
til-tauri/tauri-app/package.json
Line 10 in f97e0dc
下記を参考に ./tauri-app/eslint.config.mjs に prettier を追加
til-tauri/tauri-app/eslint.config.mjs
Line 13 in f97e0dc
./tauri-app/src-tauri をフォーマット対象から省くため下記を参考に ./.prettierignore を作成
til-tauri/tauri-app/.prettierignore
Line 1 in f97e0dc
# `./tauri-app/` で実行
yarn add -D husky下記コマンドで husky を初期化する
# `./tauri-app/` で実行
npx husky init下記を参考に自動生成される ./.husky/pre-commit を修正
til-tauri/tauri-app/.husky/pre-commit
Lines 1 to 10 in c585664
[!TIP] >
cargo fmtやcargo clippyが導入されていない場合は下記コマンドを実行して導入する# rustfmt (cargo fmt)の導入 rustup component add rustfmt# clippy (cargo clippy)の導入 rustup component add clippy
下記を参考に自動生成される ./tauri-app/package.json の script の prepare コマンドを修正
til-tauri/tauri-app/package.json
Line 13 in f97e0dc
下記コマンドを実行して, husky が参照する pre-commit ファイルを適応
# `./tauri-app/` で実行
yarn基本的には下記の Storybook 公式ドキュメントを参考に進める
yarn add -D @storybook/test-runner concurrently下記を参考に ./tauri-app/package.json の script に storybook:test, storybook:build, storybook:ci コマンドを追加
til-tauri/tauri-app/package.json
Lines 18 to 20 in 7459247
下記を参考に ./.gitignore に storybook のビルド成果物が Git 管理下に含まれないように設定を追加
til-tauri/tauri-app/.gitignore
Line 51 in 7459247
下記を参考に .github/workflows/integration-frontend.yml を作成
til-tauri/.github/workflows/integration-frontend.yml
Lines 1 to 59 in ac01169
下記を参考に .github/workflows/integration-backend.yml を作成
til-tauri/.github/workflows/integration-backend.yml
Lines 1 to 43 in 366f3a6
下記を参考に .github/workflows/integration-frontend.yml に追記
- Storybook をビルド
til-tauri/.github/workflows/integration-frontend.yml
Lines 58 to 87 in c4c0ecb
- Storybook を GitHub Pages にデプロイ
til-tauri/.github/workflows/integration-frontend.yml
Lines 89 to 100 in c4c0ecb
GitHub の設定ページから GitHub Pages を GitHub Action からデプロイするように設定
- このページ が参考になる