如何找到未使用的宝石和清理gemfile [英] How to find unused gems and cleanup gemfile

查看:112
本文介绍了如何找到未使用的宝石和清理gemfile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找简单的,但很好的方法来清理gemfile并使rails更快启动。
我如何得到所有需要的宝石与所有加载的宝石的列表。 我认为这是不可能的。当您的APP启动时,它会从Gemfile.lock中加载宝石,但它不知道它们是否需要在您的代码中(宝石)。 APP通过引发异常告诉你当某些事件调用一个未定义的类或方法时,如果某些需要的gem错过了(如果你将它从Gemfile中移除),但这可能发生在任何时候(不是在启动你的APP期间)所以如果你正在寻找清理宝石清单的方法,我认为最好的方法是手动完成它(我知道这不是一个简单的方法)。分析每个宝石,找出它提供的功能,并决定(或在代码中找到)是否需要。另外测试(如果你有他们的话)应该可以帮到你很多。


I'm looking for simple, but good way to cleanup gemfile and make rails startup faster. How can I get a list of all required gems vs all loaded gems.

解决方案

I think it is impossible. When your APP starts it loads gems from Gemfile.lock but it does not know if they (gems) are needed in your code or not. The APP inform you by raising an exception When something calls a class or method that is undefined if some needed gem is missed (if you remove it from Gemfile), but this can happen at any moment (not during starting your APP).

So if you are looking the way to clean up your gem list I think the best way to do it manually (I know it is not easy way). Analyse each gem to find out what functionality it provides and decide (or find in your code) if it is needed or not. Additionally tests (if you have them) should help you a lot.

这篇关于如何找到未使用的宝石和清理gemfile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆