From 3ccef4b69b6813c0d0e70184123a562d3f641eba Mon Sep 17 00:00:00 2001 From: Frank van Puffelen Date: Wed, 14 Aug 2024 18:19:25 -0700 Subject: [PATCH] Publish new blog post on nodemon --- notes/posts/Hot reload for Dart.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 notes/posts/Hot reload for Dart.md diff --git a/notes/posts/Hot reload for Dart.md b/notes/posts/Hot reload for Dart.md new file mode 100644 index 0000000..d8458d4 --- /dev/null +++ b/notes/posts/Hot reload for Dart.md @@ -0,0 +1,27 @@ +--- +title: Hot reload for Dart +pubDate: August 14, 2024 +alsoOn: [https://x.com/puf/status/1823887619811655723, https://www.threads.net/@frankpuf/post/C-q-yQQvqfE, https://bsky.app/profile/puf.bsky.social/post/3kzptyapr5626, https://c.im/@puf/112963363684416756] +--- + + +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](https://www.reddit.com/r/dartlang/comments/66fiop/using_dart_vms_hot_reload_feature_to_build_an/) (which is what Flutter uses), I came across this [Reddit comment](https://www.reddit.com/r/dartlang/comments/mcsgrb/comment/gs5lqkn/) that shows a much simpler solution: +``` +nodemon -x "dart run bin/server.dart" -e dart +``` + +In here: + +* `nodemon` is the [application](https://github.com/remy/nodemon) 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 execute `dart 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. + + + + + +