[英]rake assets:precompile is slow in production
我的ruby on rails應用程序大約需要半小時才能完成部署。 最長的步驟是
RAILS_ENV=production RAILS_GROUPS=assets bundle exec rake assets:precompile
大約需要1073155ms
每次部署我都需要等待很長時間。
我用
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'
嘗試跳過編譯ckeditor資產
配置/環境/ production.rb
require_relative '../../lib/assets/selective_assets_compressor'
config.assets.js_compressor = SelectiveAssetsCompressor.new
LIB /資產/ 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
為了更快地進行資產預編譯,可以在config / application.rb中將config.assets.initialize_on_precompile設置為false。 Heroku要求此為假。
config.assets.initialize_on_precompile = false
如果這樣做,請確保在本地測試rake asset:precompile,因為未加載完整的環境,因此不會加載引擎(或其他gems),這可能會導致資產丟失。
另一方面,您可以在本地部署之前執行資產預編譯並部署預編譯的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.