Rails 捆绑包只安装生产环境

我还是个新手,有点困惑。

在我们的 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..。

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

65551 次浏览

THIS ANSWER IS OUTDATED


Take a look at --without option:

bundle install --without development test

By default Bundler installs all gems and your application uses the gems that it needs. Bundler itself knows nothing about Rails and the current environment.

An alternative solution is to use the bundle-only ruby gem. It can be used as follows:

> gem install bundle-only
> bundle-only production

This library does not pollute your bundler configs or augment Gemfile.lock; it is a simple alternative to the built in bundle --without every other group option that bundler provides.