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.

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...