Rails 8 Assets: Adding a bundled package alongside vanilla setup | Radan Skorić's website

10-Apr-2025 52
Propshaft + importmap-rails works great but can’t cover all possible cases. When you start reaching for more complex npm packages, you might encounter packages that require some form of bundling. For example, let’s consider a relatively popular select UI package: Tom Select. Try pinning it: bin/importmap pin tom-select. It will appear to work, but using it will reveal it’s broken. The default build pulled from JSPM or JSDelivr isn’t completely bundled. It contains inline import calls that reference other files by relative path. These imports can’t be resolved because they reside in your application’s node_modules subfolder and aren’t exposed to the asset pipeline or included in your importmap. Does this mean switching our entire asset approach just to adopt this one package? Absolutely not, we can actually have our cake and eat it too. We can bundle just this one package and keep everything else unchanged.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle