Using Bun.js as a Bundler
shaneosullivan.wordpress.com
shaneosullivan.wordpress.com
Great writeup
We are working on the crash with the minifier + multiple entry points and hopefully will have a fix this week
> Bun inserts code that looks like this at the bottom of the built file, in this case from a file called account.ts
var account_default = {};
export {
account_default as default
};
Currently, Bun only supports esm output so for this to work you'll need `<script type="module">` instead of `<script>`. We will add support for IIFE though (which should fix this)> Hopefully Bun will implement fs.watch soon and I can throw out this code.
Yeah we need to do this. It's not super hard and we have plenty of existing code for inotify and kqueue in place for watching files, there's no good reason why we haven't done this yet.
> There’s something unfinished with Bun’s implementation of the child_process module that breaks when run in the Vercel build environment.
Currently, Bun.spawn & Bun.spawnSync (which child_process uses internally) relies on `pidfd_open` (https://man7.org/linux/man-pages/man2/pidfd_open.2.html) which Vercel, due to using AWS Lambda, does not support because it is on Linux Kernel 5.10 (3 years old). We need to add a fork() + exec() fallback for this
edit: it's not pidfd_open, but it is one of these posix_spawn related calls that is missing
(Hey Jarred - Let’s get that zig package thing done soon!)
https://facebook.github.io/watchman/ is a good workaround for now.
Roll-up for libs and webpack for apps. Only thing that works for me and all the wonky edge cases involved in building for web and node and npm and old browsers and various file types and loaders and whatnot.
Presumably those will get fixed over time, and at some point bun will just work if you want to replace your existing bundler. But even then, I personally would lean to sticking with esbuild as it’s more than fast enough for my purposes -- extra speed isn’t a compelling selling point (for me).
Gotta go with libre tools for these cases unfortunately. Nothing against Bun specifically of course, just the concept of capital + dev tools is something that must be re-learned as evil time and time again.
Overall I like Bun - diversity in JS ecosystems is a great thing - but I’m struggling to come up with reasons to actually use it (which is fine! As long as the author is enjoying the work, why not?)
edit: this is no longer the case, ignore me :)
I wish more people, or at least more HN commenters, had this attitude. Don't have to look hard to find negativity in response to folks getting out there and having a go. How many passion projects went nowhere* but taught authors valuable shit that lead to incredible engineering and projects? Besides, I love writing software and anyone who says I shouldn't because it isn't going to be better than the status quo can beat it.
*not implying Bun is going nowhere. Be gone, pedants.
This is like when esbuild first appeared level's of excitement to me. Can't wait to try it out.
A second issue with the default minification is that it broke my app in strange ways that I could not track down – I’m guessing that it’s rewriting the code in some way that is not fully stable yet. I solved it by turning off the syntax minification option
Rest sounds nice:)
Thank you to the Bun team for the work you're doing.
Thanks also to OP - the success of tooling depends upon the work of both the project and the early adopters willing to put in the work like OP did (seems substantial and motivated at least partly by sheer challenge/intellectual curiosity).
While it's definitely not ready for the mainstream, it's still a very interesting project.
Now, go make some Gifs in the Animation section!
Bun is really sweet tech. I think a good benchmark for it being ready is being able to run Nestjs.