选择命令行版本:
🌐 Synopsis
npm prune [[<@scope>/]<pkg>...]
🌐 Description
此命令会删除“多余”的软件包。如果提供了软件包名称,则仅删除与提供的名称匹配的软件包。
🌐 This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.
多余的包是指存在于 node_modules 文件夹中,但未被列为任何包的依赖的包。
🌐 Extraneous packages are those present in the node_modules folder that are not listed as any package's dependency list.
如果指定了 --omit=dev 标志或将 NODE_ENV 环境变量设置为 production,此命令将移除在你的 devDependencies 中指定的软件包。
🌐 If the --omit=dev flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.
如果使用 --dry-run 标志,则实际上不会进行任何更改。
🌐 If the --dry-run flag is used then no changes will actually be made.
如果使用 --json 标志,那么 npm prune 所做的更改(或使用 --dry-run 本应做的更改)将以 JSON 对象的形式打印出来。
🌐 If the --json flag is used, then the changes npm prune made (or would have made with --dry-run) are printed as a JSON object.
在正常操作中,额外的模块会被自动修剪,因此你通常只需要在使用 --production 标志时才使用这个命令。不过,在现实中,操作并不总是“正常”的。当发生崩溃或错误时,这个命令可以帮助清理由此产生的垃圾。
🌐 In normal operation, extraneous modules are pruned automatically, so you'll only need this command with the --production flag. However, in the real world, operation is not always "normal". When crashes or mistakes happen, this command can help clean up any resulting garbage.
🌐 Configuration
omitNODE_ENV 环境变量设置为 'production',则为 'dev',否则为空。要从磁盘上的安装树中省略的依赖类型。
🌐 Dependency types to omit from the installation tree on disk.
请注意,这些依赖仍然会被解析并添加到 package-lock.json 或 npm-shrinkwrap.json 文件中。它们只是没有实际安装到磁盘上。
🌐 Note that these dependencies are still resolved and added to the package-lock.json or npm-shrinkwrap.json file. They are just not physically installed on disk.
如果某种封装类型同时出现在 --include 和 --omit 列表中,那么它将被包括在内。
🌐 If a package type appears in both the --include and --omit lists, then it will be included.
如果生成的省略列表包含 'dev',那么所有生命周期脚本的 NODE_ENV 环境变量将被设置为 'production'。
🌐 If the resulting omit list includes 'dev', then the NODE_ENV environment variable will be set to 'production' for all lifecycle scripts.
dry-run表示你不希望 npm 做出任何更改,并且它只应该报告本来会做的事情。这个选项可以传递给任何修改本地安装的命令,例如 install、update、dedupe、uninstall,以及 pack 和 publish。
🌐 Indicates that you don't want npm to make any changes and that it should only report what it would have done. This can be passed into any of the commands that modify your local installation, eg, install, update, dedupe, uninstall, as well as pack and publish.
注意:其他与网络相关的命令(例如 dist-tags、owner 等)不支持此项。
🌐 Note: This is NOT honored by other network related commands, eg dist-tags, owner, etc.
json是否输出 JSON 数据,而不是正常输出。
🌐 Whether or not to output JSON data, rather than the normal output.
npm pkg set 中,它可以在将值保存到你的 package.json 之前使用 JSON.parse() 解析设置的值。并非所有 npm 命令都支持。
🌐 Not supported by all npm commands.
foreground-scripts在前台进程中运行已安装包的所有构建脚本(即 preinstall、install 和 postinstall 脚本),并与主 npm 进程共享标准输入、输出和错误。
🌐 Run all build scripts (ie, preinstall, install, and postinstall) scripts for installed packages in the foreground process, sharing standard input, output, and error with the main npm process.
请注意,这通常会使安装运行速度变慢,并且噪音更大,但对调试很有用。
🌐 Note that this will generally make installs run slower, and be much noisier, but can be useful for debugging.
ignore-scripts如果为 true,npm 不会运行 package.json 文件中指定的脚本。
🌐 If true, npm does not run scripts specified in package.json files.
请注意,明确用于运行特定脚本的命令,例如 npm start、npm stop、npm restart、npm test 和 npm run-script,如果设置了 ignore-scripts,仍会运行其指定的脚本,但它们不会运行任何前置或后置脚本。
🌐 Note that commands explicitly intended to run a particular script, such as npm start, npm stop, npm restart, npm test, and npm run-script will still run their intended script if ignore-scripts is set, but they will not run any pre- or post-scripts.
workspace启用在当前项目的已配置工作区的上下文中运行命令,同时通过仅运行此配置选项定义的工作区进行过滤。
🌐 Enable running a command in the context of the configured workspaces of the current project while filtering by running only the workspaces defined by this configuration option.
workspace 配置的有效值为以下之一:
🌐 Valid values for the workspace config are either:
对于 npm init 命令设置时,可以将其设置为一个尚不存在的工作区文件夹,以创建该文件夹并将其作为项目内全新的工作区进行设置。
🌐 When set for the npm init command, this may be set to the folder of a workspace which does not yet exist, to create the folder and set it up as a brand new workspace within the project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
workspaces设置为 true 以在 所有 配置的工作区上下文中运行命令。
🌐 Set to true to run the command in the context of all configured workspaces.
将此显式设置为 false 会导致像 install 这样的命令完全忽略工作区。如果不显式设置:
🌐 Explicitly setting this to false will cause commands like install to ignore workspaces altogether. When not set explicitly:
node_modules 树操作的命令(安装、更新等)会将工作区链接到 node_modules 文件夹。- 执行其他操作的命令(测试、执行、发布等)会在根项目上运行,除非 在 workspace 配置中指定了一个或多个工作区。此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
include-workspace-root为命令启用工作区时包括工作区根。
🌐 Include the workspace root when workspaces are enabled for a command.
当为 false 时,通过 workspace 配置指定单个工作区,或通过 workspaces 标志指定所有工作区,将导致 npm 仅在指定的工作区上操作,而不会在根项目上操作。
🌐 When false, specifying individual workspaces via the workspace config, or all workspaces via the workspaces flag, will cause npm to operate only on the specified workspaces, and not on the root project.
此值不会导出到子进程的环境中。
🌐 This value is not exported to the environment for child processes.
install-links当设置文件时:协议依赖将作为常规依赖被打包和安装,而不会创建符号链接。此选项对工作区没有影响。
🌐 When set file: protocol dependencies will be packed and installed as regular dependencies instead of creating a symlink. This option has no effect on workspaces.
🌐 See Also