有没有办法防止rails在生产中预编译资产? [英] Is there a way to prevent rails to precompile assets on production?

查看:89
本文介绍了有没有办法防止rails在生产中预编译资产?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有很多资产。服务器中的预编译任务非常慢,并且会耗尽主机(CPU利用率100%,平均延迟较高)。

I have a lot of assets in my project. The precompile task in the server is very slow and exhaust the host (CPU utilization 100%, high average latency).

我的想法是预编译本地主机和将所有已预编译的文件发送给GIT(主)。

My idea is to precompile all assets in my localhost and send to GIT (master) all files already precompiled.

在部署操作( cap生产部署)中,避免

In the deploy action (cap production deploy), avoid the precompile task and in the server, prevent any precompile task.

服务器使用通过 capistrano ,可以在GIT中使用。

The server uses the already precompiled files sended via capistrano, available in GIT.

有可能吗?如果是,该怎么办?
如果没有,还有另一种解决方案来避免服务器预编译资产?

Is it possible? If yes, how to do? If no, there's another solution to avoid server precomile assets?

在我的配置下面:

Gemfile

gem 'capistrano-rails', group: :development
gem 'capistrano-faster-assets', '~> 1.0', group: :development

Capfile

require 'capistrano/setup'
require 'capistrano/deploy'
require 'capistrano/rails'
require 'capistrano/faster_assets'

# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }

config / environments / production.rb

config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
config.assets.compile = true
config.assets.digest = true
other assets configs in this file is commented

环境信息

OS: Ubuntu 14.04.2 LTS (GNU/Linux 3.13.0-48-generic x86_64)
ruby -v: ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
rails -v: 4.2.3
nginx -v: nginx/1.8.0
passenger -v: 5.0.10

如果您需要更多信息,请在评论中告诉我。

If you need more information, tell me on the comments.

推荐答案

简短答案:



替换

Short answer:

Replace

require 'capistrano/rails'

require 'capistrano/rails/migrations'
require 'capistrano/bundler'



为什么起作用:



当您需要 capistrano / rails ,您确实包括以下内容():

Why this works:

When you require capistrano/rails, you are really including the following (source):

require 'capistrano/bundler'
require 'capistrano/rails/assets'
require 'capistrano/rails/migrations'

每个都可以包括在内分别获得这些功能。根据文档: https://github.com/capistrano/rails#usage

Each of these can be included separately to get just those pieces of functionality. Per the docs: https://github.com/capistrano/rails#usage

这篇关于有没有办法防止rails在生产中预编译资产?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆