[HN Gopher] Using Bun.js as a Bundler
___________________________________________________________________
Using Bun.js as a Bundler
Author : shaneos
Score : 32 points
Date : 2023-05-17 21:46 UTC (1 hours ago)
(HTM) web link (shaneosullivan.wordpress.com)
(TXT) w3m dump (shaneosullivan.wordpress.com)
| arendtio wrote:
| Actually, I find kidzfun.art much more interesting than yet
| another js bundler ;-)
| shaneos wrote:
| Glad to hear it! My kids love it which keeps me working on it.
| Having your ideal testers living with you is an amazing plus
| :-)
| revskill wrote:
| But it's not related ?
| shaneos wrote:
| It's the project I integrated Bun with as a bundler, thereby
| running into all these issues. I figured that others would
| hit the same problems so write this post about how to work
| around them
| afavour wrote:
| This is awesome but in case anyone was wondering: the author was
| previously using Webpack rather than a newer generation tool. So
| the speed benefits outlined here would likely be the same if they
| were still using Node with esbuild instead.
|
| 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?)
| paulddraper wrote:
| You can see at the beginning of the article a benchmark
| comparison with Webpack and esbuild.
| brundolf wrote:
| They weren't using SWC? They describe deploying to Vercel, and
| Next.js has had stable built-in support for SWC for a good
| while now
| hu3 wrote:
| > After a few hours of work, reading up on Bun and working my way
| through these issues, I now have a much simpler build system that
| runs in the blink of an eye. My Vercel build times have reduced
| from 2 minutes to just 50 seconds (that's all React stuff &
| fetching node_modules). My watch script runs in a few
| milliseconds instead of 5 or more seconds, My code is much
| simpler and I've removed Webpack, Browserify and Uglify from my
| projects.
|
| This is like when esbuild first appeared level's of excitement to
| me. Can't wait to try it out.
| Jarred wrote:
| (I work on Bun)
|
| 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
| brundolf wrote:
| Good to see some real anecdotes. Bun makes big promises, so I've
| been really curious to see how the reality lines up right now
| (and not just in a hypothetical future)
___________________________________________________________________
(page generated 2023-05-17 23:00 UTC)