-
Notifications
You must be signed in to change notification settings - Fork 790
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
Asset later in pipeline overwrites previous asset? #740
Comments
No it's not the correct behavior. Sprockets has a custom error called How are you adding the asset file to your pipeline? |
@brenogazzola thanks for a quick reply! |
Changing your file's name or path is, AFAIK, the only way to fix this. Both Sprockets and Propshaft are built in a way where it is impossible to have two files with the same logical path without one getting overwritten (sprockets) or dropped (propshaft). |
Well that's what I want - for it to get overwritten. I don't need both files, I want my file to be used instead of the provided file. |
The correct behavior is the That said, as you noticed, that line uses I think (not sure) you can solve that with an initializer. Rails.application.config.to_prepare do
asset = Rails.root.join("assets/image/dir/img.jpg")
Rails.application.config.assets.paths.delete asset
Rails.application.config.assets.paths << asset
end This should ensure that your asset is the last in the paths array and therefore the last to go through the |
Thanks. I couldn't find any trace of Spree doing any patching of Sprockets, so I'm not sure how this is happening. |
@brenogazzola at the time I took your explanation as proof that it's not Sprockets' fault, but now I'm digging into this again and I'm not sure anymore. The # Public: Find all assets matching pattern set in environment.
#
# Returns Enumerator of Assets.
def find(*args, &block)
# ...
promises = args.flatten.map do |path|
# this loop resets `linked_paths` in Sprockets::Base#find_all_linked_assets on each iteration
Concurrent::Promise.execute(executor: executor) do
environment.find_all_linked_assets(path).to_a
end
end So actually, there are multiple versions of the same filename that get compiled and are therefore present in Specifically in my case, these are the args/paths in above
I think the In any case, I end up with 2 versions of the same Do you have any insight on this? |
Also, changing the order of the manifests in |
I am wondering if this is expected/by design behavior - I have a gem which provides let's say
assets/image/dir/img.jpg
. Then in my app I provide my own version of this in my app assets. In development this works as expected. However if doing assets precompile, it will use the gem's asset.I think this behavior is caused by this line, which will keep the last asset that comes with the same logical path:
sprockets/lib/sprockets/manifest.rb
Line 187 in 6fcc0d1
Is this correct behavior or is this a bug?
The text was updated successfully, but these errors were encountered: