如何让Rails从插件加载中排除一些捆绑的宝石?

时间:2021-07-15 07:16:24

I have a Rails application that uses Bundler for dependency management. I've got the following in my Gemfile:

我有一个使用Bundler进行依赖关系管理的Rails应用程序。我的Gemfile中有以下内容:

# default group:
gem 'json'

group 'development' do
  gem 'my_profiler'
end

group 'test' do
  gem 'mocha'
end

group 'deployment' do
  gem 'foo'
end

I call Bundler.setup(:default, RAILS_ENV.to_sym) and Bundler.require(:default, RAILS_ENV.to_sym) in my initializers.

我在初始化程序中调用Bundler.setup(:default,RAILS_ENV.to_sym)和Bundler.require(:default,RAILS_ENV.to_sym)。

The problem is that since Bundler puts the gems into vendor/bundle/, Rails initializes all gems that have an init.rb, not just those for the current environment. How do I prevent Rails from automatically loading Foo's init.rb?

问题在于,由于Bundler将gem放入vendor / bundle /,Rails会初始化所有拥有init.rb的gem,而不仅仅是当前环境的gem。如何防止Rails自动加载Foo的init.rb?

2 个解决方案

#1


1  

What version of bundler are you using? recent ones should not install in vendor

您使用的是什么版本的捆绑包?最近的不应该安装在供应商

#2


11  

You can use the --without flag to exclude environments

您可以使用--without标志来排除环境

$ bundle install --without development test

http://gembundler.com/groups.html

#1


1  

What version of bundler are you using? recent ones should not install in vendor

您使用的是什么版本的捆绑包?最近的不应该安装在供应商

#2


11  

You can use the --without flag to exclude environments

您可以使用--without标志来排除环境

$ bundle install --without development test

http://gembundler.com/groups.html