在 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
:
npx depcheck
这篇关于在 package.json 中查找未使用的 npm 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!