4 ms·
> - I wired together live reloading plumbing using easily using the file watcher. Can you expand on that? I was looking for something that lets me reload JS co
by brabel 2y ago
> - I wired together live reloading plumbing using easily using the file watcher.
Can you expand on that? I was looking for something that lets me reload JS code just yesterday, and apparently the recommended way to do it is to restart the process :D.
- christophilus 2y agoOK. I just took a look at the project, and I was wrong. I'm not using the file watcher anymore because I change my architecture (from an SPA to a traditional server-rendered application). I run bun in `--watch` mode which means the server restarts when I make changes. The live-reload logic is around 100 LOC. To make the client refresh when the server restarts, I wrote a little middleware function that runs in dev mode, but not production. It inspects the response, and if it detects a `text/html` response, it replaces `</body>` with `<script>...</script></body>` where the script performs a long-poll fetch to an endpoint that the middleware also injects (listening on `/{someuuid}`). If the long-poll connection drops, the client begins a reconnect loop, and once it reconnects, it reloads. That's the gist of it, anyway. It's not as complex as it sounds, and it works quite well for my needs.
- FuckButtons 2y agoIn general I’ve found watchexec super useful since you can wire together arbitrary build steps, which once they get to unwieldy or ossified go into a just file.