Reputation: 5346
I'm still new to rails/ruby/bundler and am a little confused.
In our config/application.rb
file there's this bundler segment:
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
and in our Gemfile
we use different groups, e.g.
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
But when I run RAILS_ENV=production bundle install
(or bundle install --deployment
), it still installs gems from the development/test group...
Why does this happens or how can I make this work properly?
Upvotes: 96
Views: 73251
Reputation: 4447
The --without
flag is deprecated because it relies on being remembered across bundler invocations, which bundler will no longer do in future versions.
Instead use bundle config set --local without 'production'
Flags passed to bundle install or the Bundler runtime, such as --path foo or --without production, are remembered between commands and saved to your local application's configuration (normally, ./.bundle/config).
However, this will be changed in bundler 3, so it's better not to rely on this behavior. If these options must be remembered, it's better to set them using bundle config (e.g., bundle config set --local without 'production').
source: https://bundler.io/v2.4/man/bundle-config.1.html#REMEMBERING-OPTIONS
Upvotes: 3
Reputation: 20639
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.
Upvotes: 200
Reputation: 28305
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.
Upvotes: 3