Is it possible to override gemfile for local development?

强颜欢笑 提交于 2019-12-19 07:35:47

问题


We have a Gemfile currently in our git repository. However, there's a gem I use only locally in my environment (my team doesn't use it). In order to use it, I have to add it to our Gemfile, but every time I check out to our master/dev main branch, I have to remove it because of conflicts with the tracked gemfile.

What I would like is something like a Gemfile.local which would inherit the gems imported from the Gemfile but to also allow new gems to be imported there to use on my machine only. This file would be ignored in .gitignore. Is this even possible?


回答1:


Set BUNDLE_GEMFILE environment variable:

BUNDLE_GEMFILE=Gemfile.local bundle exec rails c

To provide a “delta” only in the Gemfile.local put require_relative 'Gemfile' on top of it (or Bundler::Dsl#eval_gemfile as suggested by @MichaelKohl in comments.)




回答2:


Put below code at the top of your Gemfile.local to load existing gemfile:

if File.exists?('Gemfile') then
  eval File.read('Gemfile')
end

It will load all gems from existing Gemfile. You can add new gems also as you need.

Run below commands to install gems from new Gemfile.local:

bundle install --gemfile=Gemfile.local


来源:https://stackoverflow.com/questions/48863711/is-it-possible-to-override-gemfile-for-local-development

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!