Gemfile – 将生产gem与开发gem分开
所以我知道在Gemfile中我可以这样做:
group :development, :test do gem 'gem1' gem 'gem2' end
我想要完成的是这样的事情:
group :production do gem 'gem1' gem 'gem2' end group :development, :test do gem 'gem1', :path => '/Documents/Code/gem1/' gem 'gem2', :path => '/Documents/Code/gem2/' end
所以我们的应用程序使用了我们也在本地开发的2个gem。 为了在我们的本地机器上进行开发时缩短时间,我们希望能够将我们的开发环境指向gem的本地副本 – 这样它就可以获取所有更改而无需重新启动rails服务器。 否则,我们将不得不重建gem,重新安装gem,并在gem中的每次开发更改时重新启动rails。
但是,这样做会给我以下错误:
You cannot specify the same gem twice coming from different sources. You specified that gem1 (>= 0) should come from an unspecfied source and source at /Documents/Code/gem1
我甚至试过运行像bundle install --without production
这样的东西 – 没有bundle install --without production
,我得到了同样的错误。
有谁知道我是否有可能做我想做的事情?
谢谢!
我认为有一种支持的方式来做它和一些黑客来解决它。
支持方式:
使用bundle config
和local
选项,如下所述: http : //bundler.io/v1.3/man/bundle-config.1.html
hacky方式:
在生产中使用之前使用env vars并执行bundler: http : //www.cowboycoded.com/2010/08/10/using-2-sources-for-a-gem-in-different-environments-with-bundler/
在github上有一个针对此问题的function请求,其中包含几个相关问题和许多评论: https : //github.com/carlhuda/bundler/issues/396
链接到的github问题已解决,并且与支持的方式一致。
我在文档中挖掘,你需要设置配置变量并更新你的gemfile以引用分支。
例如
编辑你的Gemfile:
gem , git: , branch:
在命令行上:
bundle config local.
我通过创建一个与原始Gemfile相同的新Gemfile解决了这个问题,除了目标gem的源代码。 然后,在config / boot.rb中,我使用了:
require 'rails' if Rails.env.development? ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../DevGemfile', __FILE__) else ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../ProdGemfile', __FILE__) end