-
Notifications
You must be signed in to change notification settings - Fork 791
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
Images in engines: Asset was not declared to be precompiled in production. #426
Comments
You need to use I recently had the same problem with a gem, and found that by explicitly including the CSS file in https://github.com/richpeck/exception_handler/blob/master/lib/exception_handler/engine.rb#L19
If you give me a link to your repo, I will be able to give pointers if you need. |
Thanks Richard, that's strange hey? Is there a reason why images in the main applications assets/images (and recursively) are automatically added to the precompile list but the same isn't the case for engines? Does sprockets add a link_tree behind the scenes for the main applications assets/images directory? I often don't have an associated css file in an engine, and these images are referenced from a view:
Does that mean I'd need to add the Is there a way to replicate that happens in the main application where the entire images directory is precompiled? Ideally (since we have about 25 engines) I'd like to be able to just glob those out in one place perhaps in an initialiser. Unfortunately my application isn't publicly accessible. Depending on what I hear back from you (if I can't figure it out after that), I'll make an example app and point you to that :D Thanks again for your help Richard, it's really appreciated :) |
I'm not sure why Engine assets are not added to the precompilation list. I used to add all the images to If you don't have any CSS file available, why not add the globbed filepath to your
If there is no other place to call the directives, you may have to although it will be extremely hacky. I found our solution by observing what I am experimenting with adding a |
Ok, I've figured it all out. Searching through the Which tipped me off about the new http://eileencodes.com/posts/the-sprockets-4-manifest/ You can see the new file at railsdiff: http://railsdiff.org/4.2.7.1/5.0.0.1
Though since https://github.com/rails/sprockets-rails/blob/v3.2.0/lib/sprockets/railtie.rb#L104 and I noticed the concept of My solution was to add this to LOOSE_COMPONENT_ASSETS = lambda do |logical_path, filename|
Dir.glob(Rails.root.join('components/**/app/assets')).any? do |assets_directory|
filename.start_with?(assets_directory) &&
!['.js', '.css', ''].include?(File.extname(logical_path))
end
end
Rails.application.config.assets.precompile += [LOOSE_COMPONENT_ASSETS] It works great so far :) I'm sure there's a way to access a list of engines currently being used in the application and I'll leave this open unless you think this is the best solution? |
Thanks again Richard, just saw your update. My method seems to be working well and operates the same way as the base application. I didn't realise one could pass a lambda to |
Oh, and the solution is moot given it's all about to change when manifest files come into force. On on Rails 4.2 so I'll just be careful not to upgrade sprockets again before Rails 5.0 :) |
No problem, glad you got it working.
Don't forget to close the issue if you fixed it! |
Thanks Richard, will do. Hope this helps others who encounter the same problem. |
Expected behavior
Prior to upgrading to Sprockets 3 I had image assets within my engine's directory at locations like:
assets/images/folder1/folder2/image.png
These images would be automatically precompiled. Images were always automatically precompiled without having to specify them in the precompile list weren't they?
Actual behavior
Now I get the error message:
Images nested deep in folders in the main app's assets/images directory are precompiled fine without needing to be declared.
System configuration
3.7.0
2.1.9
Example App
I'm happy to make one once I've confirmed that my assumptions about images and precompilation are correct on Sprockets 3.
The text was updated successfully, but these errors were encountered: