Integrating ActionCable with Webpacker in Rails 5.1

I am upgrading my application from Rails 5.0 to 5.1, and there is one thing that I cannot find anywhere else: using Webpacker to process ActionCable JavaScript files.

I understand that the Webpacker and asset pipeline should work side by side, but now that we have created Webpack in Rails, it would be impractical to use it for files located in the assets directory (where ActionCable lives), but I can not find any information about how to do it.

I'm particularly interested in Babel, so I could use ES6. Any ideas?

+6
source share
2 answers

The problem here is that you need to replace the ActionCable implementation of the rails, which is written for stars, with something written in the module syntax in order to use the web wrapper correctly. In particular, this line in your cable.js require action_cable Everything else should be easily portable. It seems that there are a couple implementations for ActionCable and modules around: https://www.npmjs.com/search?q=keywords:ActionCable

In particular, it looks exactly what you are looking for: https://www.npmjs.com/package/actioncable-modules

There seems to be some movement on the Rails side for using Webpacker as a complete replacement for stars in Rails 6, so it might be worth the wait, rather than creating something based on third-party modules.

0
source

Now there is the official npm module: https://www.npmjs.com/package/actioncable

0
source

Source: https://habr.com/ru/post/1268406/


All Articles