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

前端之家收集整理的这篇文章主要介绍了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.

原文链接:https://www.f2er.com/javaschema/283055.html

猜你在找的设计模式相关文章