在package.json中找到未使用的npm软件包 [英] Find unused npm packages in package.json
问题描述
有没有办法确定您的package.json文件中是否有不再需要的软件包?
Is there a way to determine if you have packages in your package.json file that are no longer needed?
例如,当试用一个程序包并稍后注释或删除代码但忘记卸载它时,我最终得到了几个可以删除的程序包.
For instance, when trying out a package and later commenting or deleting code, but forgetting to uninstall it, I end up with a couple packages that could be deleted.
确定软件包是否可以安全删除的有效方法是什么?
What would be an efficient way to determine if a package could safely be deleted?
推荐答案
您可以使用名为 depcheck的npm模块. (至少需要Node版本10).
You can use an npm module called depcheck (requires at least version 10 of Node).
-
安装模块:
Install the module:
npm install depcheck -g
or
yarn global add depcheck
运行它并找到未使用的依赖项:
Run it and find the unused dependencies:
depcheck
这种方法的优点是您不必记住find
或grep
命令.
The good thing about this approach is that you don't have to remember the find
or grep
command.
要运行无需安装,请使用npx:
To run without installing use npx:
npx depcheck
这篇关于在package.json中找到未使用的npm软件包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!