耙子资产:预编译:Rails 4 中的 nodigest [英] rake assets:precompile:nodigest in Rails 4
问题描述
在 Rails 3 中有一个 rake assets:precompile:nodigest 任务,它编译资产并在/public/assets 目录中编写没有摘要部分的资产.在 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?
推荐答案
Rails 4.0.0 中使用的 sprockets-rails
版本不再支持非消化资产.
The version of sprockets-rails
used in Rails 4.0.0 no longer supports non-digest assets.
只编译摘要文件名.静态非消化资产应该简单地公开存在
Only compiles digest filenames. Static non-digest assets should simply live in public
因此,任何需要静态的资产都可以手动放入您的 public
文件夹中.如果您需要复制已编译的资产,例如 SCSS 文件等,此 rake 任务可能会有所帮助(source):
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
这篇关于耙子资产:预编译:Rails 4 中的 nodigest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!