Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rake assets:precompile:nodigest in Rails 4

In Rails 3 there was a rake assets:precompile:nodigest task which was compiling assets and writing them without the digest part in /public/assets directory. In Rails 4 this has been removed, and by default all assets are precompiled with digest only. For various reasons I need also non-digested version of some of the assets. Is there any easy way to enable back the old behavior?

like image 485
Zbyszek Avatar asked Jul 08 '13 21:07

Zbyszek


1 Answers

The version of sprockets-rails used in Rails 4.0.0 no longer supports non-digest assets.

Per sprocket-rails's Readme:

Only compiles digest filenames. Static non-digest assets should simply live in public

So any assets that need to be static can be manually put into your public folder. If you need to copy compiled assets such as SCSS files, etc., this rake task may help (source):

task non_digested: :environment do
  assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
  regex = /(-{1}[a-z0-9]{32}*\.{1}){1}/
  assets.each do |file|
    next if File.directory?(file) || file !~ regex

    source = file.split('/')
    source.push(source.pop.gsub(regex, '.'))

    non_digested = File.join(source)
    FileUtils.cp(file, non_digested)
  end
end
like image 78
Dylan Markow Avatar answered Sep 25 '22 23:09

Dylan Markow