Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets from rails engine don't get compiled properly #549

Open
jacobtjackson opened this issue Feb 6, 2025 · 3 comments
Open

Assets from rails engine don't get compiled properly #549

jacobtjackson opened this issue Feb 6, 2025 · 3 comments
Labels

Comments

@jacobtjackson
Copy link

I've got a project with a rails engine mounted in it, and we're working through upgrading from an older version of Webpacker to Shakapacker. The setup for the rails engine is pretty similar to the instructions found here, with one addition: we also enhanced the assets:precompile task to run the task in our engine when it is being run from the main rails directory.

Rake::Task['assets:precompile'].enhance do
  Rake::Task['my_engine:webpacker:yarn_install'].invoke
  Rake::Task['my_engine:webpacker:compile'].invoke
end

I've been trying to modify it to work with shakapacker, but I'm running into issues. The assets:precompile task no longer adds the packs to the public folder for our rails engine, so the tests in our CI process are breaking. Is there a better guide available on how to set up shakapacker for a mounted/nested rails engine? Or can anyone help me troubleshoot and figure out what I'm doing wrong? Is the better option to install the shakapacker gem in both the main app as well as the rails engine and run rails shakapacker:install from the engine? I've got the shakapacker js library installed along with its dependencies, and I'm using

@webpacker ||= ::Shakapacker::Instance.new(
        root_path: ROOT_PATH,
        config_path: ROOT_PATH.join("config/webpacker.yml")
      )

instead of using the Webpacker instance from the guide. I can provide other config files as well if they will help, I just didn't want to make this issue extremely long.

@tomdracz
Copy link
Collaborator

Haven't used Shakapacker in engines before really and it seems like it might take some setup.

The linked guide feels sensible, not entirely sure what would need to change in Shakapacker.

To help us debug, we could really use a reproduction repo, if you can provide one. Something barebones mimicing your repo would do, doesn't need to be too complex

@jacobtjackson
Copy link
Author

@tomdracz Ok, that's what I was afraid of. I'll try to spin one up soon, I moved on to some other stuff at work so it might take a bit but I'll tag you when I'm able to circle back to it and get a reproduction up. Appreciate you offering to help troubleshoot!

@tomdracz
Copy link
Collaborator

No worries @jacobtjackson Keep me posted. As a start, if you ping here the shakapacker.yml used in your app and engine and any related webpack configs, it might spark some ideas.

Do I get this right that this worked on Webpacker? If so, what version? That might help me pinpoint also when we could have introduced something that breaks this flow.

And lastly, is the behaviour any different if you were to run the engine task separately or does that result in no output whatsoever?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants