为什么Rails4放弃对“资产"的支持? Gemfile中的组 [英] Why did Rails4 drop support for "assets" group in the Gemfile

查看:82
本文介绍了为什么Rails4放弃对“资产"的支持? Gemfile中的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Rails 3中,将专门用于在资产管道中生成资产的gem正确放置在Gemfile的assets组中:

In Rails 3, gems used exclusively to generate assets in the asset pipeline were properly placed in the assets group of the Gemfile:

...

# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', :platforms => :ruby
end

现在,根据(仍在进行中)升级文档:

Now, according to the (still in progress) upgrade documentation:

Rails 4.0从Gemfile中删除了资产组.升级时,您需要从Gemfile中删除该行.

Rails 4.0 removed the assets group from Gemfile. You'd need to remove that line from your Gemfile when upgrading.

果然,使用RC1进行新项目会产生一个Gemfile,其中默认包含任何组之外的资产相关的gem:

Sure enough, making a new project with RC1 yields a Gemfile with asset-related gems included by default outside of any group:

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.0.rc1'

# Use sqlite3 as the database for Active Record
gem 'sqlite3'

# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0.rc1'

# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'

# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby

...

这是否意味着这些宝石现在将默认捆绑在生产版本中?如果是这样,为什么会改变主意? Rails 4是否正在朝着生产中动态生成资产的方向发展?

Does this mean these gems will now be bundled in production builds by default? If so, why the change of heart? Is Rails 4 moving towards the dynamic generation of assets in production?

推荐答案

以前,资产组的存在是为了避免生产中意外进行按需编译.由于Rails 4不再具有这种行为,因此删除资产组是合理的.

Previously the assets group existed to avoid unintended compilation-on-demand in production. As Rails 4 doesn't behave like that anymore, it made sense to remove the asset group.

对此进行了更改的提交中对此进行了详细说明.我用实际答案提取了一些引号.

This is explained in more detail in the commit that changed that. I extracted some quotes with the actual answer.

在使用咖啡模板时,可能需要(生产中的)宝石,例如咖啡架 以及现在不再按需在生产中对资产进行预编译的事实.

Some gems can be needed (in production) like coffee-rails if you are using coffee templates and the fact that now assets are not precompiled on demand in production anymore.

(未按需求在生产中进行预编译)表示如果在3.2.x的生产环境中拥有该gems并忘记进行预编译,Rails会完全按照其在开发中的工作进行操作,预编译所请求的资产.在Rails 4中,情况不再如此,因此,如果您不使用任务对资产进行预编译,则在请求资产时会得到404.

(not precompiled on demand in production) Means that if you have that gems in production environment in 3.2.x and forget to precompile, Rails will do exactly what it does in development, precompile the assets that was requested. This is not true anymore in Rails 4, so if you don't precompile the assets using the tasks you will get a 404 when the assets are requests.

这篇关于为什么Rails4放弃对“资产"的支持? Gemfile中的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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