What does HackerNews think of jsbundling-rails?

Bundle and transpile JavaScript in Rails with esbuild, rollup.js, or Webpack.

Language: Ruby

The Rails https://github.com/rails/jsbundling-rails gem lets you pick between esbuild, rollup and Webpack. If Turbopack ends up being popular then jsbundling should be able to support it.

The nice thing about Rails now is there's no massive direct integration like Webpacker once was. Now we can basically use the JS tool straight up and Rails will just look at assets in a specific directory, it doesn't matter what tool generated it.

> May be Rails should take a look as well.

I don't know what's involved with Laravel's front-end stuff but Rails is using https://github.com/rails/jsbundling-rails which lets you pick whichever front-end tool you want to use that's supported (esbuild + webpack + rollup at the moment). You're no longer bound to a specific tool that's been modified to work with Rails like the old Webpacker, instead you can use the native tool with its native configuration. Although DHH has already given an opinion on not adding Vite support in https://github.com/rails/jsbundling-rails/issues/25#issuecom..., but there is third party support for it at https://vite-ruby.netlify.app/guide/introduction.html.

Technically the Rails default is not to use any of that and instead you can use a Node-less import maps solution (personally I've gone with esbuild because there's certain things you can't do with Tailwind's pre-built binary).

esbuild with Rails 7 is extremely easy nowadays. It's pretty much running a single esbuild command with a couple of flags, there's not even a config file you need to mess around with.

They did the same thing with css with https://github.com/rails/cssbundling-rails, there's tailwind, bootstrap, bulma, postcss and dart sass that works out of the box all with their native configuration.

It's the best of both worlds. You have flexibility in being able to pick whatever you want but Rails pulls it all together to make using them easy without breaking away from using the native tool's configuration.

> (aside from the JavaScript hell still plaguing rails)

It's not too bad now, set up a Node environment and there's first class support for using vanilla esbuild or if you want to go without Node entirely there's import maps and lots of goodies at the Rails level to help you manage your JS dependencies. Technically Webpack is still supported too but it's vanilla Webpack instead of Webpacker, that's all part of the new https://github.com/rails/jsbundling-rails abstraction for using a number of different JS bundling tools with their stock set ups.

Personally I went with the esbuild + tailwind combo and it's been smooth sailing. I have an example app here https://github.com/nickjj/docker-rails-example.

> Rails 7 has abandoned JS bundling in favor of using somebody else's CDN. Have fun with that.

This isn't true. You can vendor your JS libraries and Rails will bundle them for you. It uses jsbundling-rails[1] to handle that.

https://youtu.be/mpWFrUwAN88?t=772

[1]https://github.com/rails/jsbundling-rails

You can use esbuild to your existing rails apps via the gem jsbundling-rails https://github.com/rails/jsbundling-rails

It works really well