Does the order of gems in your Gemfile make a difference?

后端 未结 2 2040
梦毁少年i
梦毁少年i 2020-12-20 11:18

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

gem \'carrierwave\'
gem \'rmagick\'

And



        
2条回答
  •  无人及你
    2020-12-20 11:32

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

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

      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'

    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


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

提交回复
热议问题