如何清理不在 package.json 中的包的 node_modules 文件夹? [英] How to clean node_modules folder of packages that are not in package.json?

查看:19
本文介绍了如何清理不在 package.json 中的包的 node_modules 文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我使用 npm install 安装项目包,它会查看要安装的模块的 package.json.一段时间后,我发现我不需要某些特定模块并从 package.json 中删除其依赖项.然后我从 package.json 中删除了一些其他模块,因为它们不再需要,而其他模块则替换为替代品.

Assume I install project packages with npm install that looks into package.json for modules to be installed. After a while I see that I don't need some specific module and remove its dependency from package.json. Then I remove some other modules from package.json because they are not needed anymore and others are replaced with alternatives.

现在我想清理 node_modules 文件夹,以便只有 package.json 中列出的模块留在那里,其余的必须去,比如 npm clean.我知道我可以手动删除它们,但想要一些很好的准备使用糖功能.

Now I want to clean node_modules folder so that only modules listed in package.json stay there and the rest must go, something like npm clean. I know I can remove them manually but would like to have some nice ready to use sugar functionality for that.

推荐答案

我想你正在寻找 npm prune

npm prune [[

此命令删除无关的"包.如果包名是提供,那么只有匹配提供的名称之一的包移除.

This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.

无关的包是未在列表中列出的包父包的依赖列表.

Extraneous packages are packages that are not listed on the parent package's dependencies list.

查看文档:https://docs.npmjs.com/cli/prune

这篇关于如何清理不在 package.json 中的包的 node_modules 文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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