はじめに
こんにちは、エンジニアのkeitaMaxです。
Flutterコマンドが長くて打つのがめんどくさいので短くしてみようと思います。
やりたいこと
widgetbookを起動するのに
flutter run -t lib/widgetbook.dart -d chrome
をするのがめんどくさいので、Makefileを使用して短くしたいです。
Makefileの作成
ルートにMakefileを作成します。
Makefile
.PHONY: book
# Run Widgetbook with optional overrides:
# make book # defaults to chrome
# make book DEVICE=macos # run on macOS
# make book ARGS="--debug" # pass extra args to flutter run
book:
flutter run -t lib/widgetbook.dart -d $(DEVICE) $(ARGS)
DEVICE ?= chrome
ARGS ?=
これでmake bookコマンドを打っただけでflutter run -t lib/widgetbook.dart -d chromeが実行されます。
実際にmake bookを実行してみると
flutter_example_app % make book
flutter run -t lib/widgetbook.dart -d chrome
Launching lib/widgetbook.dart on Chrome in debug mode...
Waiting for connection from debug service on Chrome... 7.2s
This app is linked to the debug service: ws://127.0.0.1:52446/5PTAMfFG9MI=/ws
Debug service listening on ws://127.0.0.1:52446/5PTAMfFG9MI=/ws
Flutter run key commands.
r Hot reload. 🔥🔥🔥
R Hot restart.
h List all available interactive commands.
d Detach (terminate "flutter run" but leave application running).
c Clear the screen
q Quit (terminate the application on the device).
A Dart VM Service on Chrome is available at: http://127.0.0.1:52446/5PTAMfFG9MI=
Starting application from main method in: org-dartlang-app:/web_entrypoint.dart.
The Flutter DevTools debugger and profiler on Chrome is available at:
http://127.0.0.1:9101?uri=http://127.0.0.1:52446/5PTAMfFG9MI=
こんな感じでflutter run -t lib/widgetbook.dart -d chrome が実行され、Chromeが起動されます。
おわりに
この記事での質問や、間違っている、もっといい方法があるといったご意見などありましたらご指摘していただけると幸いです。
最後まで読んでいただきありがとうございました!