Hotwire Discussion

Introducing importmap-rails with turbo-rails 0.7.0 and stimulus-rails 0.3.0

I’ve extracted the importmap functionality from the stimulus-rails gem and created a new general-purpose importmap-rails gem. This gem will form the basis for allowing modern JavaScript apps to be built with Rails 7.0 without Webpack by default. You can read more about the specifics for importmap-rails here: GitHub - rails/importmap-rails: Use ESM with importmap to manage modern JavaScript in Rails without transpiling or bundling.

I’ve released a new version of the stimulus-rails gem as version 0.3.0 without the prototype importmap mechanics, but that instead relies on what’s been made available by importmap-rails. This is a breaking change. You will need to install importmap-rails, then reference @hotwired/stimulus-autoloader via the importmap to continue, if you’re upgrading from a previous version and use the asset pipeline.

I’ve also released a new version of the turbo-rails gem as version 0.7.0 where the asset pipeline installer assumes that importmap-rails is available. No changes if you’re using this together with Webpacker.

Enjoy!

12 Likes

This sounds great. Finally, no more cache issues with bundles! Thank you.

Now, to think about dewebpackifying my app without my brain exploding.

@dhh does this mean we are moving away from Webpacker as the desired path for JS in Rails apps? Don’t get me wrong, it would ultimately make me happy, but it would mean the third JS pattern in… five years? Or is this something Hotwire-specific but Rails itself would continue to recommend Webpacker?

1 Like

I’m upgrading a production, asset pipeline Hotwire app for this now.
Getting an error because the javascripts added to the assets.rb by the importmap-rails gem are missing.

The asset “actioncable.esm.js” is not present in the asset pipeline.