Hot reload for Dart
I was writing a small Dart web server today, and got tired of constantly restarting it manually: ctrl-`, ctrl-c, up arrow, enter. I mean, it’s not a huge amount of work, but it adds up - and it’s easy to miss a step (or all of them).
After searching and getting into the weeds of how to do hot reload in Dart (which is what Flutter uses), I came across this Reddit comment that shows a much simpler solution:
nodemon -x "dart run bin/server.dart" -e dart
In here:
nodemon
is the application that does the monitoring and executing. Originally written for node, it works with any executable now.-x "dart run bin/server.dart"
tells it to executedart run bin/server.dart
. Modify that last bit to point to your main Dart file.-e dart
then tells it to monitor.dart
files for changes. If it detects a change, it kills the current process and starts a new one.
Simple, but it works - so highly recommended.