ruby 修复了rake资产:预编译任务

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 修复了rake资产:预编译任务相关的知识,希望对你有一定的参考价值。

desc "Compile all the assets named in config.assets.precompile"
task :precompile do
  # We need to do this dance because RAILS_GROUPS is used
  # too early in the boot process and changing here is already too late.
  if ENV["RAILS_GROUPS"].to_s.empty? || ENV["RAILS_ENV"].to_s.empty?
    ENV["RAILS_GROUPS"] ||= "assets"
    ENV["RAILS_ENV"]    ||= "production"
    Kernel.exec $0, *ARGV
  else
    Rake::Task["environment"].invoke

    # Ensure that action view is loaded and the appropriate sprockets hooks get executed
    ActionView::Base

    # Always calculate digests and compile files
    Rails.application.config.assets.digest = true
    Rails.application.config.assets.compile = true

    config = Rails.application.config
    env    = Rails.application.assets
    target = Pathname.new(File.join(Rails.public_path, config.assets.prefix))
    manifest = {}
    manifest_path = config.assets.manifest || target

    config.assets.precompile.each do |path|
      env.each_logical_path do |logical_path|
        if path.is_a?(Regexp)
          next unless path.match(logical_path)
        else
          next unless File.fnmatch(path.to_s, logical_path)
        end

        if asset = env.find_asset(logical_path)
          manifest[logical_path] = asset.digest_path
          filename = target.join(asset.digest_path)
          mkdir_p filename.dirname
          asset.write_to(filename)
          asset.write_to("#{filename}.gz") if filename.to_s =~ /\.(css|js)$/
        end
      end
    end

    File.open("#{manifest_path}/manifest.yml", 'w') do |f|
      YAML.dump(manifest, f)
    end
  end
end

以上是关于ruby 修复了rake资产:预编译任务的主要内容,如果未能解决你的问题,请参考以下文章

Rails 3.1.1 资产预编译 - rake 中止

Rake 资产:Heroku 错误上的预编译

运行 rake 资产预编译后,在非函数中未定义

heroku 运行 rake 资产:预编译中止,因为文件具有无效的 UTF-8 字节序列

rake assets:precompile 突然失败

ExecJS :: ProgramError:运行rake资产时意外的标记点«(»,预期的点«:»:在生产中进行预编译