Monkey patch Sprockets so that non-digest assets will be generated when ENV['SPROCKETS_NON_DIGEST'] is present
# Run locally | |
$ SPROCKETS_NON_DIGEST=true RAILS_ENV=production rake assets:precompile | |
# Heroku setup | |
$ heroku labs:enable user-env-compile | |
$ heroku config:add SPROCKETS_NON_DIGEST=true |
raise("Sprockets monkey patch for v 2.10.0. Check before moving on") unless Sprockets::VERSION == "2.10.0" | |
module Sprockets | |
class Manifest | |
def compile(*args) | |
unless environment | |
raise Error, "manifest requires environment for compilation" | |
end | |
paths = environment.each_logical_path(*args).to_a + | |
args.flatten.select { |fn| Pathname.new(fn).absolute? if fn.is_a?(String)} | |
paths.each do |path| | |
if asset = find_asset(path) | |
files[asset.digest_path] = { | |
'logical_path' => asset.logical_path, | |
'mtime' => asset.mtime.iso8601, | |
'size' => asset.bytesize, | |
'digest' => asset.digest | |
} | |
logical_path = asset.logical_path | |
assets[asset.logical_path] = asset.digest_path | |
target = File.join(dir, asset.digest_path) | |
if File.exist?(target) | |
logger.debug "Skipping #{target}, already exists" | |
else | |
logger.info "Writing #{target}" | |
asset.write_to target | |
asset.write_to "#{target}.gz" if asset.is_a?(BundledAsset) | |
end | |
if ENV['SPROCKETS_NON_DIGEST'] | |
logical_target = File.join(dir, logical_path) | |
logger.info "Writing #{logical_target}" | |
asset.write_to logical_target | |
asset.write_to "#{logical_target}.gz" if asset.is_a?(BundledAsset) | |
end | |
save | |
asset | |
end | |
end | |
end | |
end | |
end |
This comment has been minimized.
This comment has been minimized.
@pwgustafson you place it in config/initializers/ -- the files in that directory get executed in alphabetical order when the Rails environment boots. Sorry for the late response. I didn't get a notification of this comment. |
This comment has been minimized.
This comment has been minimized.
brodock
commented
Jul 16, 2015
sprockets 4.0 is under active development. Maybe it's time for a new PR there |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
pwgustafson commentedNov 19, 2013
@ryana what do I do with sprockets-patch.rb - do I need to place it somewhere or run it?