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

查看:404
本文介绍了如何清除不在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 [<name> [<name ...]]

此命令删除外部"程序包.如果包名称是 提供,则仅匹配提供的名称之一的软件包 删除.

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天全站免登陆