rake assets:precompile:nodigest in Rails 4

前端 未结 6 1436
耶瑟儿~
耶瑟儿~ 2021-01-11 17:03

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

6条回答
  •  心在旅途
    2021-01-11 17:51

    Thank you Dylan Markow, I follow his answer, but I found that there are several versions of an asset (e.g. application-0a*.css, application-9c*.css, ...) when using Capistrano so that latest one should be non-digested. Here the logic is:

    namespace :my_app do
      task non_digested: :environment do
        assets = Dir.glob(File.join(Rails.root, 'public/assets/**/*'))
        regex = /(? c[:mtime]
            candidates[non_digested] = {orig: file, mtime: file_mtime}
          end
        end
    
        # genearate
        for non_digested, val in candidates do
          FileUtils.cp(val[:orig], non_digested)
        end
      end
    end
    
    Rake::Task['assets:precompile'].enhance do
      Rake::Task['my_app:non_digested'].invoke
    end
    

    As wells as, I applied 907th's regex comment, and add hook let this task executes after precompile.

提交回复
热议问题