Open lpil opened 1 year ago
I think a watch option for the build tool itself would be neat! Not sure about watchexec as I haven't used it before, but I think having things built-in as opposed to having to download an external tool is usually preferable.
For sure. We want it to be as easy as possible. Do you have thoughts on how this should work?
I think a --watch
or -w
flag would work.
gleam run --watch
Sorry, I don't mean what would the command line flag be, I mean what would it do and how would it be implemented. I don't know what is the right way to try and build this.
Ah, my bad! I'm afraid I don't know much about how you would actually implement it, but maybe something like Hotwatch could help?
There's options for listening for filesystem events in both Rust and Erlang, but I'm not sure exactly what should happen when one of these events occurs. It's a tricky one. It would be nice if we can keep the BEAM instance running like Elixir's Phoenix, but seeing as the compiler isn't available in Gleam like it is for Elixir it's a lot trickier. I'm also not sure our design would work as well with hot code loading.
We've discussed this in the discord in the past, but I'll just leave here that I made radiate to try to solve this.
It's fairly hacky since you can't access the compiler directly from gleam, but I guess it might not be too bad for development? Not sure.
Still -- websockets is needed to get this working reliably.
Until this is solved, I wanted to share my Makefile
:
.PHONY: run
run:
watchexec --restart --verbose --clear --wrap-process=session --stop-signal SIGTERM --exts gleam --watch src/ -- "gleam run"
This watches for any file changes under src/
and restarts the server.
It would be good for the programmer not to have to ctrl-c and restart the server to see their changes.
How could we implement this? The Gleam build tool has to be run so perhaps this restart functionality wants to be built into the build tool itself, to be useful to all Gleam projects.
Or can a tool like watchexec be recommended? This would be great but when I tried it occasionally it wouldn't exit cleanly and I was unable to determine why that was. It would be fab if we could fix that issue.
We need proposals!