加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-14 01:36:11 所属栏目:百科 来源:网络整理
导读:在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
在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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读