How to pack js from a different gem/engine in Rails 6 + webpacker? It seems frustrating

I recently hit the same issue. I found it strange that there are no backwards compatability. There are a lot of gems tailored to asset pipeline. Since now “Sprockets for CSS and Webpacker for JS” is the default, all those gems need to be updated to use npm and in some cases it doesn’t make sense.

Even with webpacker as a default, shipping JS inside gem has strong advantages in some cases:

  • Gem functionality is locked to specific JS version
  • JS is small, so it’s more hassle with publish it to npm
  • Better integration experience

Specific example: Gem message_bus ships with a little js library. It’s not Rails specific, but authors tailor gem to work with asset pipeline for a better experience. With webpacker in place, it’s a big wtf moment how to integrate with it. The only solution that I managed to get working is to copy js file to the app.

In this case pain of dealing with webpacker is much greater then the pain of copy pasting code and outdated dependency.

1 Like