【问题标题】:rake assets:precompile is slow in productionrake assets:预编译在生产中很慢
【发布时间】:2014-03-09 22:46:48
【问题描述】:

我的 ruby​​ on rails 应用程序需要大约半小时才能完成部署。 最长的一步是

RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile

大约需要 1073155 毫秒

每次部署都要等很久。

我用

ckeditor
rails_admin

我猜是他们减慢了我的部署速度,但我没有证据,也不知道该怎么做

解决它,要么。

我的其他环境如下:

rails 4.0.3
ruby 2.1.1

我关于资产的 production.rb 是

config.serve_static_assets = false

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = true

# Generate digests for assets URLs.
config.assets.digest = true

# Version of your assets, change this if you want to expire all your assets.
config.assets.version = '1.0'

【问题讨论】:

标签: ruby-on-rails ruby assets production


【解决方案1】:

尝试跳过编译ckeditor资产

config/environments/production.rb

  require_relative '../../lib/assets/selective_assets_compressor'
  config.assets.js_compressor = SelectiveAssetsCompressor.new

lib/assets/selective_assets_compressor.rb

class SelectiveAssetsCompressor < Uglifier
  def initialize(options = {})
    super(options)
  end

  def compress(string)
    if string =~ /CKSource/
      string
    else
      super(string)
    end
  end
end

【讨论】:

    【解决方案2】:

    为了更快的资产预编译,您可以在 config/application.rb 中将 config.assets.initialize_on_precompile 设置为 false。 Heroku 要求这是错误的。

    config.assets.initialize_on_precompile = false
    

    如果这样做,请务必在本地测试 rake assets:precompile,因为未加载完整的环境,因此不会加载引擎(或其他 gem),这可能会导致缺少资产。

    另一方面,您可以在本地部署之前执行资产预编译并部署预编译的文件。

    【讨论】:

    • 本地预编译怎么样?这是最好的选择,因为您预编译一次并部署到预编译的所有服务器。您的版本已准备好运行。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-19
    • 1970-01-01
    • 1970-01-01
    • 2013-03-10
    • 2013-09-05
    相关资源
    最近更新 更多