asset-pipeline – 为什么Rails4在Gemfile中放弃对“assets”组的支持

在Rails 3中,专门用于在资产管道中生成资产的宝石正确地放置在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

现在,根据(仍在进行中)upgrade documentation

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

果然,使用RC1创建一个新项目会生成一个Gemfile,它包含默认情况下与任何组之外的资产相关的gem:

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

...

这是否意味着这些gem将默认捆绑在生产构建中?如果是,为什么心的变化? Rails 4是否朝着动态生成资产的方向发展?

以前,资产组存在以避免生产中的无意编译请求。由于Rails 4的行为不再像这样,删除资产组是有意义的。

这在the commit中有更详细的解释,改变了。我提取了一些报价与实际的答案。

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.

(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.

相关文章

什么是设计模式一套被反复使用、多数人知晓的、经过分类编目...
单一职责原则定义(Single Responsibility Principle,SRP)...
动态代理和CGLib代理分不清吗,看看这篇文章,写的非常好,强...
适配器模式将一个类的接口转换成客户期望的另一个接口,使得...
策略模式定义了一系列算法族,并封装在类中,它们之间可以互...
设计模式讲的是如何编写可扩展、可维护、可读的高质量代码,...