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

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

问题描述

有没有一种方法可以简单地从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.

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

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