英文:
Why Gemfile install gem even though group switch set to :production?
问题
当我像这样配置Gemfile,然后在本地环境运行"bundle install"时,即使设置了group开关,也会安装'pg'。
我的期望是在本地不安装'pg'。
尽管我的期望如此,Gemfile.lock却变成了这样。
这是代码片段。
我的环境如下。
请告诉我为什么会发生这种情况。提前致谢。
英文:
When I configure Gemfile like this, and then runs "bundle install" in local environment, bundle install 'pg' even though group switch is set.
group :production do
gem 'pg'
end
My expectation is not to install 'pg' when local.
Despite of my expectation, Gemfile.lock turns to this.
net-smtp (0.3.3)
net-protocol
nio4r (2.5.9)
nokogiri (1.15.3-x64-mingw-ucrt)
racc (~> 1.4)
pg (1.1.0)
public_suffix (5.0.1)
puma (5.6.6)
nio4r (~> 2.0)
racc (1.7.1)
rack (2.2.7)
rack-test (2.1.0)
rack (>= 1.3)
rails (7.0.6)
...
DEPENDENCIES
bootsnap
capybara
debug
importmap-rails
jbuilder
pg (= 1.1)
puma (~> 5.0)
rails (~> 7.0.4, >= 7.0.4.3)
*This is snippet.
My env is below.
Windows 11 Pro 22H2
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]
rails (7.0.4.3)
Please let me know why it happens. Thanks in advance.
答案1
得分: 3
是的,这有点违反直觉。
我们可以从Bundler文档中了解到:
> 默认情况下,'bundle install' 将安装Gemfile中所有组中的所有gem。
> 但是,您可以明确告诉Bundler使用--without选项跳过安装某些组。
所以您可以使用 bundle install --without production
来跳过安装 production
组的gem。
或者设置一个配置,这样您就不必每次都添加 -without production
选项。
$ bundle config without production
$ bundle install
英文:
Yeah, it's a bit counterintuitive.
We could know from the Bundler doc:
> By default, 'bundle install' will install all gems in all groups in your Gemfile.
> However, you can explicitly tell Bundler to skip installing certain groups with the --without option.
So you could use bundle install --without production
to skip installing production
group gems.
Or setting a config so you don't have to add -without production
option every time.
$ bundle config without production
$ bundle install
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论