3 ms·
Bun is so nice. I’m building a little, zero dependency web application just for fun. - TSX is baked in, so I’m using that as my HTML templating layer. - SQLit
by christophilus 2y ago
Bun is so nice. I’m building a little, zero dependency web application just for fun.
- TSX is baked in, so I’m using that as my HTML templating layer.
- SQLite is baked in, so I’m using that as my database.
- Bun shell replaced the need for something like “concurrently”.
- I wired together live reloading plumbing using easily using the file watcher.
Its documentation is excellent. It starts up fast. When you do need to install dependencies, that is impressively fast, too.
If you haven’t checked it out yet, I’d highly recommend it. 9/10.
(The reason for the 9 is that there are still some lingering APIs and behaviors missing from Node which might trip you up.)
- 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.
- apatheticonion 2y agoCan you share this codebase by any chance? I'd love to see what that looks like to use. I might consider that for my own future adventures
- rattray 2y agoSorry if I'm being dense/lazy, but can you give an example of what this looks like: > Bun shell replaced the need for something like “concurrently”.
- twoquestions 2y ago"Concurrently" is a nodejs library for running more than one task at once, it's necessary if you want to build Typescript and Tailwind with one call to `npm run build`, for example. It's kind of a PITA to use, and just calling a Bun script is better.
- rattray 2y agoRight; what does it look like with bun?
- christophilus 2y agoI'm not on my machine where the project is, but it looks something like this: await Promise.all([ $`bun watch:server`, $`bun watch:tailwind`, $`bun watch:client`, ]);
- moralestapia 2y agoHow's that different from: await Promise.all([ child_process.exec(...), child_process.exec(...), child_process.exec(...), ]); Syntax might be off but you get the idea ...
- christophilus 2y agoIt's probably not different. It works the way I want it to / expect it to in Bun, where with Node's process.* functions, I always run into a footgun before I get it working properly.
- 2y ago