Skip to main content
Version: 9.x

设置 (.npmrc)

pnpm 从命令行、环境变量和 .npmrc 文件获取其配置。

¥pnpm gets its configuration from the command line, environment variables, and .npmrc files.

pnpm config 命令可用于更新和编辑用户和全局 .npmrc 文件的内容。

¥The pnpm config command can be used to update and edit the contents of the user and global .npmrc files.

四个相关文件是:

¥The four relevant files are:

  • 每个项目的配置文件 (/path/to/my/project/.npmrc)

    ¥per-project configuration file (/path/to/my/project/.npmrc)

  • 每个工作区的配置文件(包含 pnpm-workspace.yaml 文件的目录)

    ¥per-workspace configuration file (the directory that contains the pnpm-workspace.yaml file)

  • 每用户配置文件 (~/.npmrc)

    ¥per-user configuration file (~/.npmrc)

  • 全局配置文件(/etc/npmrc

    ¥global configuration file (/etc/npmrc)

所有 .npmrc 文件都是 key = value 参数的 INI-formatted 列表。

¥All .npmrc files are an INI-formatted list of key = value parameters.

.npmrc 文件中的值可能包含使用 ${NAME} 语法的环境变量。环境变量也可以指定默认值。如果未设置 NAME,则使用 ${NAME-fallback} 将返回 fallback。如果 NAME 未设置或者为空字符串,则 ${NAME:-fallback} 将返回 fallback

¥Values in the .npmrc files may contain env variables using the ${NAME} syntax. The env variables may also be specified with default values. Using ${NAME-fallback} will return fallback if NAME isn't set. ${NAME:-fallback} will return fallback if NAME isn't set, or is an empty string.

依赖提升设置

¥Dependency Hoisting Settings

hoist

  • 默认:true

    ¥Default: true

  • 类型:boolean

    ¥Type: boolean

true 时,所有依赖都提升到 node_modules/.pnpm/node_modules。这使得 node_modules 内的所有包都可以访问未列出的依赖。

¥When true, all dependencies are hoisted to node_modules/.pnpm/node_modules. This makes unlisted dependencies accessible to all packages inside node_modules.

hoist-workspace-packages

  • 默认:true

    ¥Default: true

  • 类型:boolean

    ¥Type: boolean

true 时,工作区中的包将符号链接到 <workspace_root>/node_modules/.pnpm/node_modules<workspace_root>/node_modules,具体取决于其他提升设置(hoist-patternpublic-hoist-pattern)。

¥When true, packages from the workspaces are symlinked to either <workspace_root>/node_modules/.pnpm/node_modules or to <workspace_root>/node_modules depending on other hoisting settings (hoist-pattern and public-hoist-pattern).

hoist-pattern

  • 默认:['*']

    ¥Default: ['*']

  • 类型:string[]

    ¥Type: string[]

告诉 pnpm 哪些包应该提升到 node_modules/.pnpm/node_modules。默认情况下,所有包都会被吊起 - 但是,如果你知道只有某些有缺陷的包具有幻像依赖,则可以使用此选项专门提升幻像依赖(推荐)。

¥Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules. By default, all packages are hoisted - however, if you know that only some flawed packages have phantom dependencies, you can use this option to exclusively hoist the phantom dependencies (recommended).

例如:

¥For instance:

hoist-pattern[]=*eslint*
hoist-pattern[]=*babel*

你还可以使用 ! 从提升中排除模式。

¥You may also exclude patterns from hoisting using !.

例如:

¥For instance:

hoist-pattern[]=*types*
hoist-pattern[]=!@types/react

public-hoist-pattern

  • 默认:['eslint', 'prettier']

    ¥Default: ['eslint', 'prettier']

  • 类型:string[]

    ¥Type: string[]

hoist-pattern 将依赖提升到虚拟存储内的隐藏模块目录不同,public-hoist-pattern 将与模式匹配的依赖提升到根模块目录。提升到根模块目录意味着应用代码将有权访问幻像依赖,即使它们不正确地修改了解析策略。

¥Unlike hoist-pattern, which hoists dependencies to a hidden modules directory inside the virtual store, public-hoist-pattern hoists dependencies matching the pattern to the root modules directory. Hoisting to the root modules directory means that application code will have access to phantom dependencies, even if they modify the resolution strategy improperly.

当处理一些有缺陷且无法正确解析依赖的可插入工具时,此设置非常有用。

¥This setting is useful when dealing with some flawed pluggable tools that don't resolve dependencies properly.

例如:

¥For instance:

public-hoist-pattern[]=*plugin*

注意:设置 shamefully-hoisttrue 与设置 public-hoist-pattern* 相同。

¥Note: Setting shamefully-hoist to true is the same as setting public-hoist-pattern to *.

你还可以使用 ! 从提升中排除模式。

¥You may also exclude patterns from hoisting using !.

例如:

¥For instance:

public-hoist-pattern[]=*types*
public-hoist-pattern[]=!@types/react

shamefully-hoist

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

默认情况下,pnpm 创建半严格 node_modules,这意味着依赖可以访问未声明的依赖,但 node_modules 之外的模块则不能。通过这种布局,生态系统中的大多数软件包都可以正常工作。但是,如果某些工具仅在提升的依赖位于 node_modules 的根目录中时才起作用,则可以将其设置为 true 来为你提升它们。

¥By default, pnpm creates a semistrict node_modules, meaning dependencies have access to undeclared dependencies but modules outside of node_modules do not. With this layout, most of the packages in the ecosystem work with no issues. However, if some tooling only works when the hoisted dependencies are in the root of node_modules, you can set this to true to hoist them for you.

Node 模块设置

¥Node-Modules Settings

modules-dir

  • 默认:node_modules

    ¥Default: node_modules

  • 类型:path

    ¥Type: path

将安装依赖的目录(而不是 node_modules)。

¥The directory in which dependencies will be installed (instead of node_modules).

node-linker

  • 默认:isolated

    ¥Default: isolated

  • 类型:isolated, hoisted, pnp

    ¥Type: isolated, hoisted, pnp

定义应使用什么链接器来安装 Node 包。

¥Defines what linker should be used for installing Node packages.

  • isolated - 依赖从 node_modules/.pnpm 处的虚拟存储进行符号链接。

    ¥isolated - dependencies are symlinked from a virtual store at node_modules/.pnpm.

  • hoisted - 创建了一个没有符号链接的扁平 node_modules。与 npm 或 Yarn Classic 创建的 node_modules 相同。当使用此设置时,Yarn 的库之一用于提升。使用此设置的正当理由:

    ¥hoisted - a flat node_modules without symlinks is created. Same as the node_modules created by npm or Yarn Classic. One of Yarn's libraries is used for hoisting, when this setting is used. Legitimate reasons to use this setting:

    1. 你的工具不能很好地处理符号链接。React Native 项目很可能只有在使用提升的 node_modules 时才能工作。

      ¥Your tooling doesn't work well with symlinks. A React Native project will most probably only work if you use a hoisted node_modules.

    2. 你的项目已部署到无服务器托管提供商。某些无服务器提供商(例如 AWS Lambda)不支持符号链接。此问题的另一种解决方案是在部署之前打包应用。

      ¥Your project is deployed to a serverless hosting provider. Some serverless providers (for instance, AWS Lambda) don't support symlinks. An alternative solution for this problem is to bundle your application before deployment.

    3. 如果你想用 "bundledDependencies" 发布你的包。

      ¥If you want to publish your package with "bundledDependencies".

    4. 如果你正在使用 --preserve-symlinks 标志运行 Node.js。

      ¥If you are running Node.js with the --preserve-symlinks flag.

  • pnp - no node_modules。Plug'n'Play 是针对 Node 由 Yarn Berry 使用 的创新策略。当使用 pnp 作为链接器时,建议将 symlink 设置为 false

    ¥pnp - no node_modules. Plug'n'Play is an innovative strategy for Node that is used by Yarn Berry. It is recommended to also set symlink setting to false when using pnp as your linker.

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

symlink 设置为 false 时,pnpm 将创建一个不带任何符号链接的虚拟存储目录。与 node-linker=pnp 一起使用是一个有用的设置。

¥When symlink is set to false, pnpm creates a virtual store directory without any symlinks. It is a useful setting together with node-linker=pnp.

enable-modules-dir

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

false 时,pnpm 不会向模块目录(node_modules)写入任何文件。当模块目录与用户空间(FUSE)中的文件系统一起安装时,这非常有用。有一个实验性的 CLI,允许你使用 FUSE 挂载模块目录:@pnpm/mount-modules

¥When false, pnpm will not write any files to the modules directory (node_modules). This is useful for when the modules directory is mounted with filesystem in userspace (FUSE). There is an experimental CLI that allows you to mount a modules directory with FUSE: @pnpm/mount-modules.

virtual-store-dir

  • 默认:node_modules/.pnpm

    ¥Default: node_modules/.pnpm

  • 类型:path

    ¥Types: path

包含存储链接的目录。项目的所有直接和间接依赖都链接到此目录中。

¥The directory with links to the store. All direct and indirect dependencies of the project are linked into this directory.

这是一个有用的设置,可以解决 Windows 上的长路径问题。如果你有一些路径很长的依赖,你可以在驱动器的根目录中选择一个虚拟存储(例如 C:\my-project-store)。

¥This is a useful setting that can solve issues with long paths on Windows. If you have some dependencies with very long paths, you can select a virtual store in the root of your drive (for instance C:\my-project-store).

或者你可以将虚拟存储设置为 .pnpm 并将其添加到 .gitignore。这将使堆栈跟踪更清晰,因为依赖的路径将高一个目录。

¥Or you can set the virtual store to .pnpm and add it to .gitignore. This will make stacktraces cleaner as paths to dependencies will be one directory higher.

注意:虚拟存储不能在多个项目之间共享。每个项目都应该有自己的虚拟存储(共享根目录的工作区除外)。

¥NOTE: the virtual store cannot be shared between several projects. Every project should have its own virtual store (except for in workspaces where the root is shared).

virtual-store-dir-max-length

添加于:v9.1.0

¥Added in: v9.1.0

  • 默认:120

    ¥Default: 120

  • 类型:number

    ¥Types: number

设置虚拟存储目录 (node_modules/.pnpm) 内目录名称的最大允许长度。如果你在 Windows 上遇到长路径问题,可以将其设置为较低的数字。

¥Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm). You may set this to a lower number if you encounter long path issues on Windows.

package-import-method

  • 默认:auto

    ¥Default: auto

  • 类型:自动、硬链接、复制、克隆、克隆或复制

    ¥Type: auto, hardlink, copy, clone, clone-or-copy

控制从存储导入包的方式(如果要禁用 node_modules 内的符号链接,则需要更改 node-linker 设置,而不是此设置)。

¥Controls the way packages are imported from the store (if you want to disable symlinks inside node_modules, then you need to change the node-linker setting, not this one).

  • auto - 尝试从存储克隆包。如果不支持克隆,则从存储硬链接包。如果克隆和链接都不可能,则退回到复制

    ¥auto - try to clone packages from the store. If cloning is not supported then hardlink packages from the store. If neither cloning nor linking is possible, fall back to copying

  • hardlink - 来自存储的硬链接包

    ¥hardlink - hard link packages from the store

  • clone-or-copy - 尝试从存储克隆包。如果不支持克隆,则退回到复制

    ¥clone-or-copy - try to clone packages from the store. If cloning is not supported then fall back to copying

  • copy - 从存储复制包

    ¥copy - copy packages from the store

  • clone - 从存储克隆(又名写入时复制或参考链接)包

    ¥clone - clone (AKA copy-on-write or reference link) packages from the store

克隆是将包写入 node_modules 的最佳方法。这是最快的方法,也是最安全的方法。使用克隆时,你可以编辑 node_modules 中的文件,并且它们不会在中央内容可寻址存储中被修改。

¥Cloning is the best way to write packages to node_modules. It is the fastest way and safest way. When cloning is used, you may edit files in your node_modules and they will not be modified in the central content-addressable store.

不幸的是,并非所有文件系统都支持克隆。我们建议使用写时复制 (CoW) 文件系统(例如,Linux 上的 Btrfs 而不是 Ext4),以获得 pnpm 的最佳体验。

¥Unfortunately, not all file systems support cloning. We recommend using a copy-on-write (CoW) file system (for instance, Btrfs instead of Ext4 on Linux) for the best experience with pnpm.

modules-cache-max-age

  • 默认:10080(7 天分钟)

    ¥Default: 10080 (7 days in minutes)

  • 类型:number

    ¥Type: number

应从模块目录中删除孤立包的时间(以分钟为单位)。pnpm 在模块目录中保留包的缓存。这可以提高切换分支或降级依赖时的安装速度。

¥The time in minutes after which orphan packages from the modules directory should be removed. pnpm keeps a cache of packages in the modules directory. This boosts installation speed when switching branches or downgrading dependencies.

dlx-cache-max-age

  • 默认:1440(1 天的分钟数)

    ¥Default: 1440 (1 day in minutes)

  • 类型:number

    ¥Type: number

dlx 缓存过期的时间(以分钟为单位)。执行 dlx 命令后,pnpm 会保留一个缓存,该缓存会省略后续调用同一 dlx 命令的安装步骤。

¥The time in minutes after which dlx cache expires. After executing a dlx command, pnpm keeps a cache that omits the installation step for subsequent calls to the same dlx command.

存储设置

¥Store Settings

store-dir

  • 默认:

    ¥Default:

    • 如果设置了 $PNPM_HOME 环境变量,则 $PNPM_HOME/store

      ¥If the $PNPM_HOME env variable is set, then $PNPM_HOME/store

    • 如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm/store

      ¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store

    • 在 Windows 上:~/AppData/Local/pnpm/store

      ¥On Windows: ~/AppData/Local/pnpm/store

    • 在 macOS 上:~/Library/pnpm/store

      ¥On macOS: ~/Library/pnpm/store

    • 在 Linux 上:~/.local/share/pnpm/store

      ¥On Linux: ~/.local/share/pnpm/store

  • 类型:path

    ¥Type: path

所有包在磁盘上的保存位置。

¥The location where all the packages are saved on the disk.

该存储应始终位于进行安装的同一磁盘上,因此每个磁盘将有一个存储。如果当前磁盘上有主目录,则在其中创建存储。如果磁盘上没有主目录,则在文件系统的根目录下创建存储。例如,如果安装发生在安装在 /mnt 的文件系统上,则存储将在 /mnt/.pnpm-store 创建。Windows 系统也是如此。

¥The store should be always on the same disk on which installation is happening, so there will be one store per disk. If there is a home directory on the current disk, then the store is created inside it. If there is no home on the disk, then the store is created at the root of the filesystem. For example, if installation is happening on a filesystem mounted at /mnt, then the store will be created at /mnt/.pnpm-store. The same goes for Windows systems.

可以从不同的磁盘设置存储,但在这种情况下,pnpm 将从存储中复制包而不是硬链接它们,因为硬链接只能在同一文件系统上使用。

¥It is possible to set a store from a different disk but in that case pnpm will copy packages from the store instead of hard-linking them, as hard links are only possible on the same filesystem.

verify-store-integrity

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

默认情况下,如果存储中的文件已被修改,则在将其链接到项目的 node_modules 之前会检查该文件的内容。如果 verify-store-integrity 设置为 false,则在安装过程中不会检查内容寻址存储中的文件。

¥By default, if a file in the store has been modified, the content of this file is checked before linking it to a project's node_modules. If verify-store-integrity is set to false, files in the content-addressable store will not be checked during installation.

use-running-store-server

危险

已弃用的功能

¥Deprecated feature

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

仅允许使用存储服务器进行安装。如果没有正在运行的存储服务器,安装将失败。

¥Only allows installation with a store server. If no store server is running, installation will fail.

strict-store-pkg-content-check

添加于:v9.4.0

¥Added in: v9.4.0

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

某些注册表允许在不同的包名称和/或版本下发布完全相同的内容。这会破坏存储中软件包的有效性检查。为了避免在存储中验证此类软件包的名称和版本时出现错误,你可以将 strict-store-pkg-content-check 设置设置为 false

¥Some registries allow the exact same content to be published under different package names and/or versions. This breaks the validity checks of packages in the store. To avoid errors when verifying the names and versions of such packages in the store, you may set the strict-store-pkg-content-check setting to false.

锁定文件设置

¥Lockfile Settings

lockfile

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

当设置为 false 时,pnpm 将不会读取或生成 pnpm-lock.yaml 文件。

¥When set to false, pnpm won't read or generate a pnpm-lock.yaml file.

prefer-frozen-lockfile

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

当设置为 true 并且可用的 pnpm-lock.yaml 满足 package.json 依赖指令时,将执行无头安装。无头安装会跳过所有依赖解析,因为它不需要修改锁定文件。

¥When set to true and the available pnpm-lock.yaml satisfies the package.json dependencies directive, a headless installation is performed. A headless installation skips all dependency resolution as it does not need to modify the lockfile.

lockfile-include-tarball-url

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

将软件包 tarball 的完整 URL 添加到 pnpm-lock.yaml 中的每个条目。

¥Add the full URL to the package's tarball to every entry in pnpm-lock.yaml.

git-branch-lockfile

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

当设置为 true 时,安装后生成的锁定文件名称将根据当前分支名称命名,以完全避免合并冲突。例如,如果当前分支名称为 feature-foo,则对应的锁文件名称将为 pnpm-lock.feature-foo.yaml,而不是 pnpm-lock.yaml。它通常与命令行参数 --merge-git-branch-lockfiles 结合使用,或者通过在 .npmrc 文件中设置 merge-git-branch-lockfiles-branch-pattern 来使用。

¥When set to true, the generated lockfile name after installation will be named based on the current branch name to completely avoid merge conflicts. For example, if the current branch name is feature-foo, the corresponding lockfile name will be pnpm-lock.feature-foo.yaml instead of pnpm-lock.yaml. It is typically used in conjunction with the command line argument --merge-git-branch-lockfiles or by setting merge-git-branch-lockfiles-branch-pattern in the .npmrc file.

merge-git-branch-lockfiles-branch-pattern

  • 默认:null

    ¥Default: null

  • 类型:数组或空值

    ¥Type: Array or null

该配置匹配当前分支名称来确定是否合并所有 git 分支 lockfile 文件。默认情况下,需要手动传递 --merge-git-branch-lockfiles 命令行参数。此配置允许该过程自动补齐。

¥This configuration matches the current branch name to determine whether to merge all git branch lockfile files. By default, you need to manually pass the --merge-git-branch-lockfiles command line parameter. This configuration allows this process to be automatically completed.

例如:

¥For instance:

merge-git-branch-lockfiles-branch-pattern[]=main
merge-git-branch-lockfiles-branch-pattern[]=release*

你还可以使用 ! 排除模式。

¥You may also exclude patterns using !.

peers-suffix-max-length

添加于:v9.3.0

¥Added in: v9.3.0

  • 默认:1000

    ¥Default: 1000

  • 类型:number

    ¥Type: number

添加到锁文件中依赖密钥的对等 ID 后缀的最大长度。如果后缀较长,则用哈希替换。

¥Max length of the peer IDs suffix added to dependency keys in the lockfile. If the suffix is longer, it is replaced with a hash.

注册表和身份验证设置

¥Registry & Authentication Settings

registry

npm 包注册表的基本 URL(包括尾部斜杠)。

¥The base URL of the npm package registry (trailing slash included).

<scope>:registry

应用于指定范围的包的 npm 注册表。例如,设置 @babel:registry=https://example.com/packages/npm/ 将强制当你使用 pnpm add @babel/core 或任何 @babel 范围的包时,将从 https://example.com/packages/npm 而不是默认注册表获取该包。

¥The npm registry that should be used for packages of the specified scope. For example, setting @babel:registry=https://example.com/packages/npm/ will enforce that when you use pnpm add @babel/core, or any @babel scoped package, the package will be fetched from https://example.com/packages/npm instead of the default registry.

<URL>:_authToken

定义访问指定注册表时要使用的身份验证承载令牌。例如:

¥Define the authentication bearer token to use when accessing the specified registry. For example:

//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

你还可以使用环境变量。例如:

¥You may also use an environment variable. For example:

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

或者你可以直接使用环境变量,根本不更改 .npmrc

¥Or you may just use an environment variable directly, without changing .npmrc at all:

npm_config_//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 

<URL>:tokenHelper

令牌助手是一个输出身份验证令牌的可执行文件。这可以用于 authToken 不是常量值而是定期刷新的情况,其中脚本或其他工具可以使用现有刷新令牌来获取新的访问令牌。

¥A token helper is an executable which outputs an auth token. This can be used in situations where the authToken is not a constant value but is something that refreshes regularly, where a script or other tool can use an existing refresh token to obtain a new access token.

辅助程序的路径配置必须是绝对路径,不带任何参数。为了安全起见,只允许在用户 .npmrc 中设置该值。否则,项目可以在项目的本地 .npmrc 中放置一个值并运行任意可执行文件。

¥The configuration for the path to the helper must be an absolute path, with no arguments. In order to be secure, it is only permitted to set this value in the user .npmrc. Otherwise a project could place a value in a project's local .npmrc and run arbitrary executables.

为默认注册表设置令牌助手:

¥Setting a token helper for the default registry:

tokenHelper=/home/ivan/token-generator

为指定注册表设置令牌助手:

¥Setting a token helper for the specified registry:

//registry.corp.com:tokenHelper=/home/ivan/token-generator

请求设置

¥Request Settings

ca

  • 默认:npm CA 证书

    ¥Default: The npm CA certificate

  • 类型:字符串、数组或 null

    ¥Type: String, Array or null

与注册表的 SSL 连接受信任的证书颁发机构签名证书。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:

¥The Certificate Authority signing certificate that is trusted for SSL connections to the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:

ca="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

设置为 null 以仅允许已知的注册商,或设置为特定 CA 证书以仅信任该特定签名机构。

¥Set to null to only allow known registrars, or to a specific CA cert to trust only that specific signing authority.

通过指定证书数组可以信任多个 CA:

¥Multiple CAs can be trusted by specifying an array of certificates:

ca[]="..."
ca[]="..."

另请参阅 strict-ssl 配置。

¥See also the strict-ssl config.

cafile

  • 默认:null

    ¥Default: null

  • 类型:path

    ¥Type: path

包含一个或多个证书颁发机构签名证书的文件的路径。与 ca 设置类似,但允许多个 CA,以及将 CA 信息存储在文件中而不是通过 CLI 指定。

¥A path to a file containing one or multiple Certificate Authority signing certificates. Similar to the ca setting, but allows for multiple CAs, as well as for the CA information to be stored in a file instead of being specified via CLI.

<URL>:cafile

定义访问指定注册表时要使用的证书颁发机构文件的路径。例如:

¥Define the path to a Certificate Authority file to use when accessing the specified registry. For example:

//registry.npmjs.org/:keyfile=client-cert.pem

cert

  • 默认:null

    ¥Default: null

  • 类型:字符串

    ¥Type: String

访问注册表时要传递的客户端证书。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:

¥A client certificate to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:

cert="-----BEGIN CERTIFICATE-----\nXXXX\nXXXX\n-----END CERTIFICATE-----"

它不是证书文件的路径。

¥It is not the path to a certificate file.

<URL>:certfile

定义访问指定注册表时要使用的证书文件的路径。例如:

¥Define the path to a certificate file to use when accessing the specified registry. For example:

//registry.npmjs.org/:certfile=server-cert.pem

key

  • 默认:null

    ¥Default: null

  • 类型:字符串

    ¥Type: String

访问注册表时传递的客户端密钥。值应采用 PEM 格式(AKA "Base-64 编码的 X.509 (.CER)")。例如:

¥A client key to pass when accessing the registry. Values should be in PEM format (AKA "Base-64 encoded X.509 (.CER)"). For example:

key="-----BEGIN PRIVATE KEY-----\nXXXX\nXXXX\n-----END PRIVATE KEY-----"

它不是密钥文件的路径(并且没有 keyfile 选项)。

¥It is not the path to a key file (and there is no keyfile option).

此设置包含敏感信息。不要将其写入提交到存储库的本地 .npmrc 文件。

¥This setting contains sensitive information. Don't write it to a local .npmrc file committed to the repository.

<URL>:keyfile

定义访问指定注册表时要使用的客户端密钥文件的路径。例如:

¥Define the path to a client key file to use when accessing the specified registry. For example:

//registry.npmjs.org/:keyfile=server-key.pem

git-shallow-hosts

  • 默认:['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']

    ¥Default: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']

  • 类型:string[]

    ¥Type: string[]

当获取 Git 存储库的依赖时,如果主机在此设置中列出,pnpm 将使用浅克隆仅获取所需的提交,而不是所有历史记录。

¥When fetching dependencies that are Git repositories, if the host is listed in this setting, pnpm will use shallow cloning to fetch only the needed commit, not all the history.

https-proxy

  • 默认:null

    ¥Default: null

  • 类型:url

    ¥Type: url

用于传出 HTTPS 请求的代理。如果设置了 HTTPS_PROXYhttps_proxyHTTP_PROXYhttp_proxy 环境变量,则将使用它们的值。

¥A proxy to use for outgoing HTTPS requests. If the HTTPS_PROXY, https_proxy, HTTP_PROXY or http_proxy environment variables are set, their values will be used instead.

如果你的代理 URL 包含用户名和密码,请确保对它们进行 URL 编码。例如:

¥If your proxy URL contains a username and password, make sure to URL-encode them. For instance:

https-proxy=https://use%21r:pas%2As@my.proxy:1234/foo

不要对用户名和密码之间的冒号 (:) 进行编码。

¥Do not encode the colon (:) between the username and password.

http-proxy

proxy

  • 默认:null

    ¥Default: null

  • 类型:url

    ¥Type: url

用于传出 http 请求的代理。如果设置了 HTTP_PROXY 或 http_proxy 环境变量,底层请求库将遵循代理设置。

¥A proxy to use for outgoing http requests. If the HTTP_PROXY or http_proxy environment variables are set, proxy settings will be honored by the underlying request library.

local-address

  • 默认:undefined

    ¥Default: undefined

  • 类型:IP 地址

    ¥Type: IP Address

连接到 npm 注册表时使用的本地接口的 IP 地址。

¥The IP address of the local interface to use when making connections to the npm registry.

maxsockets

  • 默认:网络并发数 x 3

    ¥Default: network-concurrency x 3

  • 类型:数字

    ¥Type: Number

每个源使用的最大连接数(协议/主机/端口组合)。

¥The maximum number of connections to use per origin (protocol/host/port combination).

noproxy

  • 默认:null

    ¥Default: null

  • 类型:字符串

    ¥Type: String

不应使用代理的以逗号分隔的域扩展字符串。

¥A comma-separated string of domain extensions that a proxy should not be used for.

strict-ssl

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

通过 HTTPS 向注册表发送请求时是否进行 SSL 密钥验证。

¥Whether or not to do SSL key validation when making requests to the registry via HTTPS.

另请参见 ca 选项。

¥See also the ca option.

network-concurrency

  • 默认:16

    ¥Default: 16

  • 类型:数字

    ¥Type: Number

控制同时处理的 HTTP(S) 请求的最大数量。

¥Controls the maximum number of HTTP(S) requests to process simultaneously.

fetch-retries

  • 默认:2

    ¥Default: 2

  • 类型:数字

    ¥Type: Number

如果 pnpm 无法从注册表获取,则重试多少次。

¥How many times to retry if pnpm fails to fetch from the registry.

fetch-retry-factor

  • 默认:10

    ¥Default: 10

  • 类型:数字

    ¥Type: Number

重试退避的指数因子。

¥The exponential factor for retry backoff.

fetch-retry-mintimeout

  • 默认:10000(10 秒)

    ¥Default: 10000 (10 seconds)

  • 类型:数字

    ¥Type: Number

重试请求的最小(基本)超时。

¥The minimum (base) timeout for retrying requests.

fetch-retry-maxtimeout

  • 默认:60000(1 分钟)

    ¥Default: 60000 (1 minute)

  • 类型:数字

    ¥Type: Number

确保重试因子不会使请求过长的最大回退超时。

¥The maximum fallback timeout to ensure the retry factor does not make requests too long.

fetch-timeout

  • 默认:60000(1 分钟)

    ¥Default: 60000 (1 minute)

  • 类型:数字

    ¥Type: Number

等待 HTTP 请求完成的最长时间。

¥The maximum amount of time to wait for HTTP requests to complete.

对等依赖设置

¥Peer Dependency Settings

auto-install-peers

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

true 时,将自动安装任何缺失的非可选对等依赖。

¥When true, any missing non-optional peer dependencies are automatically installed.

版本冲突

¥Version Conflicts

如果来自不同包的对等依赖存在版本要求冲突,pnpm 将不会自动安装冲突对等依赖的任何版本。相反,会打印一条警告。例如,如果一个依赖需要 react@^16.0.0,而另一个依赖需要 react@^17.0.0,则这些要求会发生冲突,并且不会发生自动安装。

¥If there are conflicting version requirements for a peer dependency from different packages, pnpm will not install any version of the conflicting peer dependency automatically. Instead, a warning is printed. For example, if one dependency requires react@^16.0.0 and another requires react@^17.0.0, these requirements conflict, and no automatic installation will occur.

解决冲突

¥Conflict Resolution

如果出现版本冲突,你需要评估自己安装哪个版本的对等依赖,或更新依赖以符合其对等依赖要求。

¥In case of a version conflict, you'll need to evaluate which version of the peer dependency to install yourself, or update the dependencies to align their peer dependency requirements.

dedupe-peer-dependents

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

当此设置设置为 true 时,具有对等依赖的包将在对等解析后进行数据去重。

¥When this setting is set to true, packages with peer dependencies will be deduplicated after peers resolution.

例如,假设我们有一个包含两个项目的工作区,并且它们的依赖中都有 webpackwebpack 在其可选对等依赖中具有 esbuild,其中一个项目在其依赖中具有 esbuild。在这种情况下,pnpm 会将 webpack 的两个实例链接到 node_modules/.pnpm 目录:一个带 esbuild,另一个不带 esbuild

¥For instance, let's say we have a workspace with two projects and both of them have webpack in their dependencies. webpack has esbuild in its optional peer dependencies, and one of the projects has esbuild in its dependencies. In this case, pnpm will link two instances of webpack to the node_modules/.pnpm directory: one with esbuild and another one without it:

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
webpack@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

这是有道理的,因为 webpack 在两个项目中使用,而其中一个项目没有 esbuild,因此这两个项目不能共享 webpack 的同一个实例。然而,这并不是大多数开发者所期望的,特别是因为在提升的 node_modules 中,只会有一个 webpack 实例。因此,当 webpack 不存在冲突的对等依赖时,你现在可以使用 dedupe-peer-dependents 设置来对 webpack 进行数据去重(解释在最后)。在这种情况下,如果我们将 dedupe-peer-dependents 设置为 true,则两个项目都将使用相同的 webpack 实例,即已解析 esbuild 的实例:

¥This makes sense because webpack is used in two projects, and one of the projects doesn't have esbuild, so the two projects cannot share the same instance of webpack. However, this is not what most developers expect, especially since in a hoisted node_modules, there would only be one instance of webpack. Therefore, you may now use the dedupe-peer-dependents setting to deduplicate webpack when it has no conflicting peer dependencies (explanation at the end). In this case, if we set dedupe-peer-dependents to true, both projects will use the same webpack instance, which is the one that has esbuild resolved:

node_modules
.pnpm
webpack@1.0.0_esbuild@1.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild

什么是冲突的对等依赖?通过冲突的对等依赖,我们指的是如下场景:

¥What are conflicting peer dependencies? By conflicting peer dependencies we mean a scenario like the following one:

node_modules
.pnpm
webpack@1.0.0_react@16.0.0_esbuild@1.0.0
webpack@1.0.0_react@17.0.0
project1
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0/node_modules/webpack
react (v17)
project2
node_modules
webpack -> ../../node_modules/.pnpm/webpack@1.0.0_esbuild@1.0.0/node_modules/webpack
esbuild
react (v16)

在这种情况下,我们无法对 webpack 进行数据去重,因为 webpack 在其对等依赖中具有 react,而 react 是从两个项目上下文中的两个不同版本解析的。

¥In this case, we cannot dedupe webpack as webpack has react in its peer dependencies and react is resolved from two different versions in the context of the two projects.

strict-peer-dependencies

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果启用此功能,如果树中缺少或无效的对等依赖,命令将失败。

¥If this is enabled, commands will fail if there is a missing or invalid peer dependency in the tree.

resolve-peers-from-workspace-root

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

启用后,根工作区项目的依赖用于解决工作区中任何项目的对等依赖。这是一个有用的功能,因为你只能在工作区的根目录中安装对等依赖,并且你可以确保工作区中的所有项目都使用相同版本的对等依赖。

¥When enabled, dependencies of the root workspace project are used to resolve peer dependencies of any projects in the workspace. It is a useful feature as you can install your peer dependencies only in the root of the workspace, and you can be sure that all projects in the workspace use the same versions of the peer dependencies.

CLI 设置

¥CLI Settings

[no-]color

  • 默认:auto

    ¥Default: auto

  • 类型:auto, always, never

    ¥Type: auto, always, never

控制输出中的颜色。

¥Controls colors in the output.

  • auto - 当标准输出是终端或 TTY 时,输出使用颜色。

    ¥auto - output uses colors when the standard output is a terminal or TTY.

  • always - 忽略端子和管道之间的差异。你很少会想要这个;在大多数情况下,如果你希望在重定向输出中使用颜色代码,则可以将 --color 标志传递给 pnpm 命令以强制其使用颜色代码。默认设置几乎总是你想要的。

    ¥always - ignore the difference between terminals and pipes. You’ll rarely want this; in most scenarios, if you want color codes in your redirected output, you can instead pass a --color flag to the pnpm command to force it to use color codes. The default setting is almost always what you’ll want.

  • never - turns off colors.这是 --no-color 使用的设置。

    ¥never - turns off colors. This is the setting used by --no-color.

loglevel

  • 默认:info

    ¥Default: info

  • 类型:debug, info, warn, error

    ¥Type: debug, info, warn, error

将显示任何等于或高于给定级别的日志。你可以改为传递 --silent 来关闭所有输出日志。

¥Any logs at or higher than the given level will be shown. You can instead pass --silent to turn off all output logs.

use-beta-cli

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

启用 CLI 测试版功能的实验选项。这意味着你可能会对 CLI 功能进行一些更改,这些更改可能是重大更改或潜在的错误。

¥Experimental option that enables beta features of the CLI. This means that you may get some changes to the CLI functionality that are breaking changes, or potentially bugs.

recursive-install

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

如果启用此选项,pnpm install 的主要行为将成为 pnpm install -r 的主要行为,这意味着安装将在所有工作区或子目录包上执行。

¥If this is enabled, the primary behaviour of pnpm install becomes that of pnpm install -r, meaning the install is performed on all workspace or subdirectory packages.

否则,pnpm install 将在当前目录中专门构建包。

¥Else, pnpm install will exclusively build the package in the current directory.

engine-strict

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果启用此功能,pnpm 将不会安装任何声称与当前 Node 版本不兼容的软件包。

¥If this is enabled, pnpm will not install any package that claims to not be compatible with the current Node version.

无论此配置如何,如果项目(不是依赖)在其 engines 字段中指定了不兼容的版本,安装将始终失败。

¥Regardless of this configuration, installation will always fail if a project (not a dependency) specifies an incompatible version in its engines field.

npm-path

  • 类型:path

    ¥Type: path

pnpm 用于某些操作(例如发布)的 npm 二进制文件的位置。

¥The location of the npm binary that pnpm uses for some actions, like publishing.

package-manager-strict

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

如果禁用此设置,如果在 package.jsonpackageManager 字段中指定了不同的包管理器,pnpm 将不会失败。启用后,只会检查软件包名称(自 pnpm v9.2.0 起),因此无论 packageManager 字段中指定的版本如何,你仍然可以运行任何版本的 pnpm。

¥If this setting is disabled, pnpm will not fail if a different package manager is specified in the packageManager field of package.json. When enabled, only the package name is checked (since pnpm v9.2.0), so you can still run any version of pnpm regardless of the version specified in the packageManager field.

或者,你可以通过将 COREPACK_ENABLE_STRICT 环境变量设置为 0 来禁用此设置。

¥Alternatively, you can disable this setting by setting the COREPACK_ENABLE_STRICT environment variable to 0.

package-manager-strict-version

添加于:v9.2.0

¥Added in: v9.2.0

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

启用后,如果 pnpm 的版本与 package.jsonpackageManager 字段中指定的版本不完全匹配,则 pnpm 将失败。

¥When enabled, pnpm will fail if its version doesn't exactly match the version specified in the packageManager field of package.json.

manage-package-manager-versions

添加于:v9.7.0

¥Added in: v9.7.0

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

启用后,pnpm 将自动下载并运行 package.jsonpackageManager 字段中指定的 pnpm 版本。这是 Corepack 使用的相同字段。示例:

¥When enabled, pnpm will automatically download and run the version of pnpm specified in the packageManager field of package.json. This is the same field used by Corepack. Example:

{
"packageManager": "pnpm@9.3.0"
}

构建设置

¥Build Settings

ignore-scripts

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

不要执行项目 package.json 及其依赖中定义的任何脚本。

¥Do not execute any scripts defined in the project package.json and its dependencies.

注意

该标志不会阻止 .pnpmfile.cjs 的执行

¥This flag does not prevent the execution of .pnpmfile.cjs

ignore-dep-scripts

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

不要执行已安装软件包的任何脚本。执行项目的脚本。

¥Do not execute any scripts of the installed packages. Scripts of the projects are executed.

child-concurrency

  • 默认:5

    ¥Default: 5

  • 类型:数字

    ¥Type: Number

同时分配以构建 node_modules 的子进程的最大数量。

¥The maximum number of child processes to allocate simultaneously to build node_modules.

side-effects-cache

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

使用并缓存(前/后)安装钩子的结果。

¥Use and cache the results of (pre/post)install hooks.

side-effects-cache-readonly

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

仅使用副作用缓存(如果存在),不要为新包创建它。

¥Only use the side effects cache if present, do not create it for new packages.

unsafe-perm

  • 默认:如果以 root 身份运行则为 false,否则为 true

    ¥Default: false IF running as root, ELSE true

  • 类型:布尔值

    ¥Type: Boolean

设置为 true 以在运行包脚本时启用 UID/GID 切换。如果明确设置为 false,则以非 root 用户身份安装将会失败。

¥Set to true to enable UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.

node-options

  • 默认:NULL

    ¥Default: NULL

  • 类型:字符串

    ¥Type: String

通过 NODE_OPTIONS 环境变量传递到 Node.js 的选项。这不会影响 pnpm 本身的执行方式,但会影响生命周期脚本的调用方式。

¥Options to pass through to Node.js via the NODE_OPTIONS environment variable. This does not impact how pnpm itself is executed but it does impact how lifecycle scripts are called.

Node.js 设置

¥Node.js Settings

use-node-version

  • 默认:undefined

    ¥Default: undefined

  • 类型:semver

    ¥Type: semver

指定项目运行时应使用哪个确切的 Node.js 版本。pnpm 将自动安装指定版本的 Node.js 并使用它来运行 pnpm run 命令或 pnpm node 命令。

¥Specifies which exact Node.js version should be used for the project's runtime. pnpm will automatically install the specified version of Node.js and use it for running pnpm run commands or the pnpm node command.

这可以用来代替 .nvmrcnvm。而不是以下 .nvmrc 文件:

¥This may be used instead of .nvmrc and nvm. Instead of the following .nvmrc file:

16.16.0

使用此 .npmrc 文件:

¥Use this .npmrc file:

use-node-version=16.16.0

此设置仅适用于工作区根目录中的 .npmrc 文件。如果你需要为工作区中的项目指定自定义 Node.js,请改用 package.jsonpnpm.executionEnv.nodeVersion 字段。

¥This setting works only in a .npmrc file that is in the root of your workspace. If you need to specify a custom Node.js for a project in the workspace, use the pnpm.executionEnv.nodeVersion field of package.json instead.

node-version

  • 默认:node -v 返回的值,不带 v 前缀

    ¥Default: the value returned by node -v, without the v prefix

  • 类型:semver

    ¥Type: semver

检查包的 engines 设置时使用的 Node.js 版本。

¥The Node.js version to use when checking a package's engines setting.

如果你想阻止项目的贡献者添加新的不兼容依赖,请在项目根目录的 .npmrc 文件中使用 node-versionengine-strict

¥If you want to prevent contributors of your project from adding new incompatible dependencies, use node-version and engine-strict in a .npmrc file at the root of the project:

node-version=12.22.0
engine-strict=true

这样,即使有人使用 Node.js v16,他们也无法安装不支持 Node.js v12.22.0 的新依赖。

¥This way, even if someone is using Node.js v16, they will not be able to install a new dependency that doesn't support Node.js v12.22.0.

node-mirror:<releaseDir>

  • 默认:https://nodejs.cn/download/<releaseDir>/

    ¥Default: https://nodejs.cn/download/<releaseDir>/

  • 类型:URL

    ¥Type: URL

设置下载 Node.js 的基本 URL。此设置的 <releaseDir> 部分可以是 [https://nodejs.cn/download]https://nodejs.cn/download 中的任何目录:releasercnightlyv8-canary

¥Sets the base URL for downloading Node.js. The <releaseDir> portion of this setting can be any directory from https://nodejs.cn/download: release, rc, nightly, v8-canary, etc.

以下是如何配置 pnpm 从中国的 Node.js 镜像下载 Node.js:

¥Here is how pnpm may be configured to download Node.js from Node.js mirror in China:

node-mirror:release=https://npmmirror.com/mirrors/node/
node-mirror:rc=https://npmmirror.com/mirrors/node-rc/
node-mirror:nightly=https://npmmirror.com/mirrors/node-nightly/

工作区设置

¥Workspace Settings

  • 默认:false

    ¥Default: false

  • 类型:true, false, deep

    ¥Type: true, false, deep

如果启用此功能,本地可用的软件包将链接到 node_modules,而不是从注册表下载。这在 monorepo 中非常方便。如果你还需要将本地包链接到子依赖,则可以使用 deep 设置。

¥If this is enabled, locally available packages are linked to node_modules instead of being downloaded from the registry. This is very convenient in a monorepo. If you need local packages to also be linked to subdependencies, you can use the deep setting.

否则,将从注册表下载并安装软件包。但是,仍然可以使用 workspace: 范围协议链接工作区包。

¥Else, packages are downloaded and installed from the registry. However, workspace packages can still be linked by using the workspace: range protocol.

prefer-workspace-packages

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果启用此功能,则工作区中的本地包优先于注册表中的包,即使注册表中存在较新版本的包也是如此。

¥If this is enabled, local packages from the workspace are preferred over packages from the registry, even if there is a newer version of the package in the registry.

仅当工作区不使用 save-workspace-protocol 时,此设置才有用。

¥This setting is only useful if the workspace doesn't use save-workspace-protocol.

shared-workspace-lockfile

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

如果启用此功能,pnpm 将在工作区的根目录中创建单个 pnpm-lock.yaml 文件。这也意味着工作区包的所有依赖都将位于单个 node_modules 中(并符号链接到其包 node_modules 文件夹以进行 Node 的模块解析)。

¥If this is enabled, pnpm creates a single pnpm-lock.yaml file in the root of the workspace. This also means that all dependencies of workspace packages will be in a single node_modules (and get symlinked to their package node_modules folder for Node's module resolution).

此选项的优点:

¥Advantages of this option:

  • 每个依赖都是一个单例

    ¥every dependency is a singleton

  • monorepo 中的安装速度更快

    ¥faster installations in a monorepo

  • 代码审查中的更改较少,因为它们都在一个文件中

    ¥fewer changes in code reviews as they are all in one file

注意

尽管所有依赖都将硬链接到根 node_modules,但包只能访问在其 package.json 中声明的那些依赖,因此保留了 pnpm 的严格性。这是上述符号链接的结果。

¥Even though all the dependencies will be hard linked into the root node_modules, packages will have access only to those dependencies that are declared in their package.json, so pnpm's strictness is preserved. This is a result of the aforementioned symbolic linking.

save-workspace-protocol

  • 默认:rolling

    ¥Default: rolling

  • 类型:true, false, rolling

    ¥Type: true, false, rolling

此设置控制如何将从工作区链接的依赖添加到 package.json

¥This setting controls how dependencies that are linked from the workspace are added to package.json.

如果 foo@1.0.0 在工作区中,并且你在工作区的另一个项目中运行 pnpm add foo,则以下是将 foo 添加到依赖字段的方式。save-prefix 设置还会影响规范的创建方式。

¥If foo@1.0.0 is in the workspace and you run pnpm add foo in another project of the workspace, below is how foo will be added to the dependencies field. The save-prefix setting also influences how the spec is created.

save-workspace-protocolsave-prefix规范
false''1.0.0
false'~'~1.0.0
false'^'^1.0.0
true''workspace:1.0.0
true'~'workspace:~1.0.0
true'^'workspace:^1.0.0
rolling''workspace:*
rolling'~'workspace:~
rolling'^'workspace:^

include-workspace-root

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

在工作区中递归执行命令时,也在根工作区项目上执行它们。

¥When executing commands recursively in a workspace, execute them on the root workspace project as well.

ignore-workspace-cycles

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

当设置为 true 时,不会打印工作区循环警告。

¥When set to true, no workspace cycle warnings will be printed.

disallow-workspace-cycles

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

当设置为 true 时,如果工作区有循环,安装将失败。

¥When set to true, installation will fail if the workspace has cycles.

其他设置

¥Other Settings

save-prefix

  • 默认:'^'

    ¥Default: '^'

  • 类型:'^'、'~'、''

    ¥Type: '^', '~', ''

配置安装到 package.json 文件的软件包版本如何添加前缀。

¥Configure how versions of packages installed to a package.json file get prefixed.

例如,如果某个软件包的版本为 1.2.3,则默认情况下其版本设置为 ^1.2.3,允许对该软件包进行小幅升级,但在 pnpm config set save-prefix='~' 之后,它将设置为 ~1.2.3,仅允许补丁升级。

¥For example, if a package has version 1.2.3, by default its version is set to ^1.2.3 which allows minor upgrades for that package, but after pnpm config set save-prefix='~' it would be set to ~1.2.3 which only allows patch upgrades.

当添加的包指定了范围时,此设置将被忽略。例如,pnpm add foo@2 会将 package.jsonfoo 的版本设置为 2,而不管 save-prefix 的值如何。

¥This setting is ignored when the added package has a range specified. For instance, pnpm add foo@2 will set the version of foo in package.json to 2, regardless of the value of save-prefix.

tag

  • 默认:latest

    ¥Default: latest

  • 类型:字符串

    ¥Type: String

如果你 pnpm add 软件包并且不提供特定版本,那么它将安装在此设置的标签下注册的版本的软件包。

¥If you pnpm add a package and you don't provide a specific version, then it will install the package at the version registered under the tag from this setting.

如果未给出显式标记,这还会设置添加到 pnpm tag 命令指定的 package@version 的标记。

¥This also sets the tag that is added to the package@version specified by the pnpm tag command if no explicit tag is given.

global-dir

  • 默认:

    ¥Default:

    • 如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm/global

      ¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/global

    • 在 Windows 上:~/AppData/Local/pnpm/global

      ¥On Windows: ~/AppData/Local/pnpm/global

    • 在 macOS 上:~/Library/pnpm/global

      ¥On macOS: ~/Library/pnpm/global

    • 在 Linux 上:~/.local/share/pnpm/global

      ¥On Linux: ~/.local/share/pnpm/global

  • 类型:path

    ¥Type: path

指定自定义目录来存储全局包。

¥Specify a custom directory to store global packages.

global-bin-dir

  • 默认:

    ¥Default:

    • 如果设置了 $XDG_DATA_HOME 环境变量,则 $XDG_DATA_HOME/pnpm

      ¥If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm

    • 在 Windows 上:~/AppData/Local/pnpm

      ¥On Windows: ~/AppData/Local/pnpm

    • 在 macOS 上:~/Library/pnpm

      ¥On macOS: ~/Library/pnpm

    • 在 Linux 上:~/.local/share/pnpm

      ¥On Linux: ~/.local/share/pnpm

  • 类型:path

    ¥Type: path

允许设置全局安装包的 bin 文件的目标目录。

¥Allows to set the target directory for the bin files of globally installed packages.

state-dir

  • 默认:

    ¥Default:

    • 如果设置了 $XDG_STATE_HOME 环境变量,则 $XDG_STATE_HOME/pnpm

      ¥If the $XDG_STATE_HOME env variable is set, then $XDG_STATE_HOME/pnpm

    • 在 Windows 上:~/AppData/Local/pnpm-state

      ¥On Windows: ~/AppData/Local/pnpm-state

    • 在 macOS 上:~/.pnpm-state

      ¥On macOS: ~/.pnpm-state

    • 在 Linux 上:~/.local/state/pnpm

      ¥On Linux: ~/.local/state/pnpm

  • 类型:path

    ¥Type: path

pnpm 创建当前仅由更新检查程序使用的 pnpm-state.json 文件的目录。

¥The directory where pnpm creates the pnpm-state.json file that is currently used only by the update checker.

cache-dir

  • 默认:

    ¥Default:

    • 如果设置了 $XDG_CACHE_HOME 环境变量,则 $XDG_CACHE_HOME/pnpm

      ¥If the $XDG_CACHE_HOME env variable is set, then $XDG_CACHE_HOME/pnpm

    • 在 Windows 上:~/AppData/Local/pnpm-cache

      ¥On Windows: ~/AppData/Local/pnpm-cache

    • 在 macOS 上:~/Library/Caches/pnpm

      ¥On macOS: ~/Library/Caches/pnpm

    • 在 Linux 上:~/.cache/pnpm

      ¥On Linux: ~/.cache/pnpm

  • 类型:path

    ¥Type: path

缓存的位置(包元数据和 dlx)。

¥The location of the cache (package metadata and dlx).

use-stderr

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

当 true 时,所有输出都写入 stderr。

¥When true, all the output is written to stderr.

update-notifier

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

设置为 false 可在使用比最新版本更旧的 pnpm 时抑制更新通知。

¥Set to false to suppress the update notification when using an older version of pnpm than the latest.

prefer-symlinked-executables

  • 默认:true,当节点链接器设置为提升且系统为 POSIX 时

    ¥Default: true, when node-linker is set to hoisted and the system is POSIX

  • 类型:布尔值

    ¥Type: Boolean

创建指向 node_modules/.bin 中可执行文件的符号链接而不是命令垫片。此设置在 Windows 上被忽略,其中只有命令填充程序起作用。

¥Create symlinks to executables in node_modules/.bin instead of command shims. This setting is ignored on Windows, where only command shims work.

ignore-compatibility-db

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

在安装过程中,某些软件包的依赖会自动修补。如果你想禁用此功能,请将此配置设置为 false

¥During installation the dependencies of some packages are automatically patched. If you want to disable this, set this config to false.

这些补丁是从 Yarn 的 @yarnpkg/extensions 包中应用的。

¥The patches are applied from Yarn's @yarnpkg/extensions package.

resolution-mode

  • 默认:最高(从 v8.0.0 到 v8.6.12 是最低直接)

    ¥Default: highest (was lowest-direct from v8.0.0 to v8.6.12)

  • 类型:highest, time-based, lowest-direct

    ¥Type: highest, time-based, lowest-direct

resolution-mode 设置为 time-based 时,依赖将通过以下方式解决:

¥When resolution-mode is set to time-based, dependencies will be resolved the following way:

  1. 直接依赖将解析为最低版本。所以如果依赖中有 foo@^1.1.0,那么就会安装 1.1.0

    ¥Direct dependencies will be resolved to their lowest versions. So if there is foo@^1.1.0 in the dependencies, then 1.1.0 will be installed.

  2. 将从最后一个直接依赖发布之前发布的版本解析子依赖。

    ¥Subdependencies will be resolved from versions that were published before the last direct dependency was published.

使用此解析模式,使用热缓存的安装速度更快。它还减少了子依赖劫持的机会,因为只有更新直接依赖,子依赖才会更新。

¥With this resolution mode installations with warm cache are faster. It also reduces the chance of subdependency hijacking as subdependencies will be updated only if direct dependencies are updated.

此解析模式仅适用于 npm 的 完整元数据。所以在某些场景下会比较慢。但是,如果你使用 Verdaccio v5.15.1 或更高版本,你可以将 registry-supports-time-field 设置设置为 true,并且速度会非常快。

¥This resolution mode works only with npm's full metadata. So it is slower in some scenarios. However, if you use Verdaccio v5.15.1 or newer, you may set the registry-supports-time-field setting to true, and it will be really fast.

resolution-mode 设置为 lowest-direct 时,直接依赖将解析为最低版本。

¥When resolution-mode is set to lowest-direct, direct dependencies will be resolved to their lowest versions.

registry-supports-time-field

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

如果你使用的注册表在缩写元数据中返回 "time" 字段,则将此设置为 true。截至目前,只有 v5.15.1 的 Verdaccio 支持此功能。

¥Set this to true if the registry that you are using returns the "time" field in the abbreviated metadata. As of now, only Verdaccio from v5.15.1 supports this.

extend-node-path

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

false 时,命令 shim 中未设置 NODE_PATH 环境变量。

¥When false, the NODE_PATH environment variable is not set in the command shims.

deploy-all-files

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

部署包或安装本地包时,会复制该包的所有文件。默认情况下,如果包的 package.json 中有 "files" 字段,则仅复制列出的文件和目录。

¥When deploying a package or installing a local package, all files of the package are copied. By default, if the package has a "files" field in the package.json, then only the listed files and directories are copied.

dedupe-direct-deps

  • 默认:false

    ¥Default: false

  • 类型:布尔值

    ¥Type: Boolean

当设置为 true 时,已符号链接到工作区根 node_modules 目录的依赖将不会符号链接到子项目 node_modules 目录。

¥When set to true, dependencies that are already symlinked to the root node_modules directory of the workspace will not be symlinked to subproject node_modules directories.

dedupe-injected-deps

  • 默认:true

    ¥Default: true

  • 类型:布尔值

    ¥Type: Boolean

启用此设置后,只要有可能,注入的依赖 就会从工作区进行符号链接。如果依赖目和注入的依赖引用相同的对等依赖,则无需将注入的依赖物理复制到依赖的 node_modules 中;符号链接就足够了。

¥When this setting is enabled, dependencies that are injected will be symlinked from the workspace whenever possible. If the dependent project and the injected dependency reference the same peer dependencies, then it is not necessary to physically copy the injected dependency into the dependent's node_modules; a symlink is sufficient.