用于卸载或修剪 Node.js 中未使用的包的 npm 命令 [英] npm command to uninstall or prune unused packages in Node.js

查看:26
本文介绍了用于卸载或修剪 Node.js 中未使用的包的 npm 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以简单地从 Node.js 项目中卸载所有未使用(未声明)的依赖项(那些不再在我的 package.json 中定义的依赖项.)当我更新我的应用程序时,我喜欢自动删除未引用的包.

Is there a way to simply uninstall all unused (undeclared) dependencies from a Node.js project (ones that are no longer defined in my package.json.) When I update my application I like to have the unreferenced packages removed automatically.

推荐答案

注意:当启用包锁时,最近的 npm 版本会自动执行此操作,因此除了删除带有 --production 标志的开发包外,这不是必需的.

Note: Recent npm versions do this automatically when package-locks are enabled, so this is not necessary except for removing development packages with the --production flag.

运行 npm prune 以删除 package.json.

来自npm help 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.

如果指定了 --production 标志,此命令将删除您的 devDependencies 中指定的包.

If the --production flag is specified, this command will remove the packages specified in your devDependencies.

这篇关于用于卸载或修剪 Node.js 中未使用的包的 npm 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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