92

我对 rails/ruby/bundle 还是新手,有点困惑。

在我们的config/application.rb文件中有这个捆绑程序段:

if defined?(Bundler)         
  # If you precompile assets before deploying to production, use this line
  Bundler.require(*Rails.groups(:assets => %w(development test)))
  # If you want your assets lazily compiled in production, use this line
  # Bundler.require(:default, :assets, Rails.env)
end

在我们的Gemfile我们使用不同的组,例如

group :development, :test do
  gem "rspec-rails", ">= 2.7.0", :group => [:development, :test]
  gem 'shoulda-matchers'
  gem 'watchr'
  gem 'spork', '~> 1.0rc'
  gem 'spectator'                          
  gem 'debugger'
  gem 'wirble'
end

但是当我运行RAILS_ENV=production bundle install(或bundle install --deployment)时,它仍然会从开发/测试组安装 gem...

为什么会发生这种情况,或者我怎样才能使它正常工作?

4

2 回答 2

191

看看--without选项:

bundle install --without development test

默认情况下,Bundler 会安装所有 gem,并且您的应用程序会使用它需要的 gem。Bundler 本身对 Rails 和当前环境一无所知。

于 2012-06-06T10:46:00.313 回答
3

另一种解决方案是使用bundle-onlyruby​​ gem。它可以按如下方式使用:

> gem install bundle-only
> bundle-only production

该库不会污染您的捆绑器配置或扩充Gemfile.lock;它是提供的内置bundle --without every other group选项的简单替代方案bundler

于 2017-06-14T09:57:08.683 回答