Created
November 15, 2015 16:21
-
-
Save seanlinsley/46031f7729a2abb79d5c to your computer and use it in GitHub Desktop.
Support undigested assets in Rails 4.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| task 'assets:precompile' => 'environment' do | |
| # See https://github.com/rails/sprockets-rails/issues/49 | |
| # | |
| # Sprockets no longer creates undigested assets, so we have to | |
| # emulate the old behavior to keep vendored JS libraries happy | |
| # | |
| # For the record, | |
| # Digested: 4-star-de4f1f10cb13e222111c8afe0b516131.jpg | |
| # Undigested: 4-star.jpg | |
| digest = /(-{1}[a-z0-9]{64}*\.{1}){1}/ | |
| assets = Dir.glob File.join Rails.root, 'public/assets/**/*' | |
| assets.each do |file| | |
| next if File.directory?(file) || file !~ digest | |
| next if File.extname(file) == '.json' # Avoid duplicate manifest | |
| source = file.split '/' | |
| source.push source.pop.gsub digest, '.' | |
| FileUtils.cp file, File.join(source) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment