Gemfile中宝石的顺序是否有所不同?

时间:2022-10-17 22:33:29

Is the order in which you list your gems important? Are these two blocks equivalent?

您列出宝石的顺序是否重要?这两个块是等价的吗?

gem 'carrierwave'
gem 'rmagick'

And

gem 'rmagick'
gem 'carrierwave'

2 个解决方案

#1


11  

When you use Bundle.require (which Rails does), Gems are required in the order they appear in the Gemfile. In wasn’t always like this, but has been this way for a while.

当您使用Bundle.require(Rails确实如此)时,Gems按照它们在Gemfile中出现的顺序是必需的。并不总是这样,但这种方式已经有一段时间了。

Since Carrierwave requires RMagick explicitly when it is needed, I don’t think it should matter in your case; but strictly speaking the two blocks are not equivalent.

由于Carrierwave在需要时明确要求RMagick,我认为这不重要;但严格来说,两个街区并不相同。

#2


6  

Bundler doesn't load gem dependencies by the order that you list them*, but it does go by source priority using this criteria:

Bundler不会按列出的顺序加载gem依赖项*,但它确实使用以下条件按源优先级:

  1. Explicit path or git options append to a gem dependency, e.g.:

    显式路径或git选项附加到gem依赖项,例如:

    gem 'some-gem', github: 'somebody/some-gem'
    
  2. Explicitly defined dependencies for gems that are otherwise required implicitly from other gem dependecies, i.e., gem 'actionmailer' gem is implicitly required by gem 'rails'

    明确定义宝石的依赖关系,否则需要隐式地从其他宝石依赖关系中获取宝石,即gem''动作邮件'宝石'

  3. If you have multiple sources added it will search from last to first.

    如果添加了多个源,它将从最后一个搜索到第一个。

See http://gembundler.com/v1.3/man/gemfile.5.html#SOURCE-PRIORITY

请参见http://gembundler.com/v1.3/man/gemfile.5.html#SOURCE-PRIORITY


* Edit: As per Matt's answer, depending on what you're trying to do (or what gems you're loading) the order MIGHT matter. See Even with bundler your gem order can be significant.

*编辑:根据马特的回答,取决于你想要做什么(或者你正在加载什么宝石),订单可能很重要。请参阅即使使用捆绑器,您的宝石订单也很重要。

#1


11  

When you use Bundle.require (which Rails does), Gems are required in the order they appear in the Gemfile. In wasn’t always like this, but has been this way for a while.

当您使用Bundle.require(Rails确实如此)时,Gems按照它们在Gemfile中出现的顺序是必需的。并不总是这样,但这种方式已经有一段时间了。

Since Carrierwave requires RMagick explicitly when it is needed, I don’t think it should matter in your case; but strictly speaking the two blocks are not equivalent.

由于Carrierwave在需要时明确要求RMagick,我认为这不重要;但严格来说,两个街区并不相同。

#2


6  

Bundler doesn't load gem dependencies by the order that you list them*, but it does go by source priority using this criteria:

Bundler不会按列出的顺序加载gem依赖项*,但它确实使用以下条件按源优先级:

  1. Explicit path or git options append to a gem dependency, e.g.:

    显式路径或git选项附加到gem依赖项,例如:

    gem 'some-gem', github: 'somebody/some-gem'
    
  2. Explicitly defined dependencies for gems that are otherwise required implicitly from other gem dependecies, i.e., gem 'actionmailer' gem is implicitly required by gem 'rails'

    明确定义宝石的依赖关系,否则需要隐式地从其他宝石依赖关系中获取宝石,即gem''动作邮件'宝石'

  3. If you have multiple sources added it will search from last to first.

    如果添加了多个源,它将从最后一个搜索到第一个。

See http://gembundler.com/v1.3/man/gemfile.5.html#SOURCE-PRIORITY

请参见http://gembundler.com/v1.3/man/gemfile.5.html#SOURCE-PRIORITY


* Edit: As per Matt's answer, depending on what you're trying to do (or what gems you're loading) the order MIGHT matter. See Even with bundler your gem order can be significant.

*编辑:根据马特的回答,取决于你想要做什么(或者你正在加载什么宝石),订单可能很重要。请参阅即使使用捆绑器,您的宝石订单也很重要。