res-x icon indicating copy to clipboard operation
res-x copied to clipboard

Use native bun bundler

Open samwightt opened this issue 6 months ago • 3 comments

Hi, was wondering if it’s possible to use the native bun bundler instead of Vite with this? Mainly wondering because I’m wanting to compile into a single file executable, and I don’t think (?) bun will include assets by default unless you use the bun bundler. I believe the bun bundler has a plugin API similar to Vite’s but can’t verify how good it is or not. Is there something Vite is specifically needed for for asset management?

Amazing project by the way, I’ve never been so excited to try using a library!

samwightt avatar Jun 23 '25 19:06 samwightt

Yeah I think so, I don't see any reason why this couldn't be made to work with Bun's bundler and asset pipeline instead of Vite's. I haven't been able to make Vite work exactly how I want to anyway, so it's definitely something that would be interesting.

Glad you're excited! It's used in prod in quite a few places, so even if the README and examples probably leaves a bit to desire at times, it's all working well. Please do report back with your experiences.

zth avatar Jun 23 '25 19:06 zth

Would you be open to a PR that adds Bun as a bundler option?

samwightt avatar Jun 24 '25 16:06 samwightt

Definitely! But I think the goal needs to be exploring if we can get rid of VIte entirely in favor of only Bun. And what type of trade offs that would include.

This is roughly what the Vite integration does today:

  1. Provides an asset pipeline for everything non-JS - processing and hashing things in the assets folder, like images/fonts/whatever
  2. Provides hot reload for CSS. This however isn't working as well as I'd hoped, and it also makes less sense with Tailwind where you need the HTML to hot reload as well, since that's what controls the classes
  3. Provides hot reload for HTML. This isn't working well either, turned out to be quite complicated (needs to rerequest exact page, and then merge the resulting HTML with the current HTML so it doesn't wipe form state etc). Could maybe be revisited with Bun
  4. Bundles the ResX client. But this we could just ship as a prebundled lib, no reason for the asset pipeline of the consuming project to handle this

What it doesn't do but should:

  1. Provide a good solid way of easily processing and bundling JS for the client. Remember, ResX ships no client JS by default outside of the tiny ResX client, and optionally HTMX if you use that.

The part about being able to bundle and process JS for multiple entrypoints is interesting. I think we could build something quite cool where you could essentially render a script tag and import a ReScript file dynamically to it, and then have that be autobundled with no effort. This would allow some pretty cool integrations where you could move things across the BE/FE seamlessly.

So, if you'd be up for trying to see if the above could be replaced by Bun, then that'd be great!

zth avatar Jun 26 '25 06:06 zth