How to find unused gems and cleanup gemfile

痴心易碎 提交于 2019-12-21 04:15:08

问题


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.


回答1:


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.




回答2:


bundle clean --force will remove old gems (or older versions of currently-used gems) previously installed, but not currently being used in your current Gemfile.lock manifest.




回答3:


It depends what you're after here.

If you're looking to remove old, unused gem versions, then bundle clean.

If you've been adding gems as you develop and have lost track of the ones you actually use, and have good test coverage, then try this answer.

If you want to reduce the number of gems rails pulls in at startup to the bare minimum, try gem_bench.




回答4:


First, if you want to check what are the gems used by your project, I invite you to run gem server in your project folder root, then go to http://0.0.0.0:8808/

You will be able to understand the dependencies of all the gems your project is using. It will also show you all versions of the same gem.

To remove old versions of gems you can run as @changingrainbows mention bundle clean --force

After this step run your gem server again and watch the result, a clean and understandable gem list with all dependencies.



来源:https://stackoverflow.com/questions/19167563/how-to-find-unused-gems-and-cleanup-gemfile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!