All threads / How to use ESBuild in Rails with JSBundling Discussion

Ask A Question


You’re not receiving notifications from this thread.

How to use ESBuild in Rails with JSBundling Discussion

This is awesome, I have been using it for a couple of weeks now. I didn’t necessarily think webpacker was slow, except maybe on Heroku builds. But when you use this, you wonder why you put up with webpacker for so long :)


Does it make sense to have esbuild-rails built into Rails? And should the esbuild.config.js file go in the /config folder or do files in that folder have to be Ruby?

Not really. They tried that with webpacker and it didn't work because things change so often and every app needs flexibility to adjust for their use case.

The way JSbundling is setup, you can use any tools you want. The only requirement is they dump to the asset pipeline. That's super flexible and you can make any changes you need. Great balance I'd say.


you can do so with bundling or code-splitting, plugins, and more.


I am trying to run away from my webpack. Is it possible to handle react with jsx plus scss files imported ? Especially, scss files are located in app/javascript ?

JSX/React, yeah esbuild actually comes with support for JSX and typescript I believe, all built in with no configuration needed.

As far as SCSS is concerned, the best approach would be to use cssbundling-rails and have a separate build task just for the SCSS files. You could point this task to app/javascript/styles/app.scss or similar, it just needs to output the built file to app/assets/builds/*.css.

You may even consider looking into vite-ruby.
Vite uses esbuild for building the JS, but it also lets you build your CSS just as fast with built in live reloading.

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,130+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.