Skip to main content

Using webpacker in Rails Engines?

Rails • Asked by Johan André

I'm making a pluggable CMS engine and want to keep the JS/CSS (preferably by writing Tailwind components) in the engine. It works great with models, controllers, routes and the asset pipeline, but I really can't figure out the best way to do it with Webpacker-packs.

Any tips?


Hi Johan! Have you seen this issue? https://github.com/rails/webpacker/issues/348

Yes! Thank you! Basically it says that there is no good way (right now) to use webpacker in engines. :(

Hi Johan, I'm working on Webpacker engine integration for my company and we found a beautiful solution. You can use our generator to add webpacker support on the engine (for the development) and read the documentation to complete the integration of the engine on the main application with the assets compilation. Here is the link: https://github.com/ideonetwork/dakarai#engine-webpacker

Here there is also a description of how this method works and how it should be integrated on the Webpacker core (see the last post).
https://github.com/rails/webpacker/issues/348

Thanks Gregorio! Will check it out! 

It would be super cool if Chris could cover this. Nobody in that github issue thread has found an official answer to this, and the official README from the rails/webpacker repository just doesn't work as intended. At least not for me.

This is something I've been struggling with for a long time, and apparently so has a lot of other people. There are unanswered StackOverflow posts, unanswered reddit posts, and of course, that entire issue ticket which has ideas but no solutions. There are a few solutions, but they're hacky, and don't work for everyone

Even if the only good solution right now is hacky, that's probably enough for most peoples' needs until someone creates a good solution. I'd love to contribute, but I don't have enough rails and/or webpacker knowledge yet to do so.

This thread started on GoRails started about a year and half ago, and there still isn't a clear answer anywhere. There wasn't a clear answer in rails 5, and there still isn't an answer in rails 6, even with the now released stable version.

Again, it seems that way. If there is some article on the internet some where that explains how to have a rails 6 engine with webpacker that can either server compiled assets to the parent app, or let the parent app be responsible for compiling its own assets as well as all the engines assets to which it's connected, please point me to it.

Thanks,
Angel.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 22,346+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.