跳到主内容
版本:10.x

设置 (.npmrc)

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

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

四个相关文件分别为:

  • per-project configuration file (/path/to/my/project/.npmrc)
  • per-workspace configuration file (the directory that contains the pnpm-workspace.yaml file)
  • per-user configuration file (~/.npmrc)
  • global configuration file (/etc/npmrc)

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

Values in the .npmrc files may contain env variables using the ${NAME} syntax. 也可以使用默认值指定环境变量。 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.

依赖提升设置

hoist

  • 默认值:true
  • 类型:Boolean

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
  • 类型:Boolean

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: ['*']
  • Type: string[]

Tells pnpm which packages should be hoisted to node_modules/.pnpm/node_modules. 默认情况下,所有包都被提升 — 但是,如果你知道只有某些有缺陷的包具有幻影依赖,你可以使用此选项专门提升幻影依赖(推荐做法)。

例如:

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

You may also exclude patterns from hoisting using !.

例如:

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

public-hoist-pattern

  • Default: []
  • Type: string[]

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. 提升至根模块目录中意味着应用代码可以访问到幻影依赖,即使它们对解析策略做了不当的修改。

当处理一些不能正确解析依赖关系的有缺陷可插拔工具时,此设置很有用。

例如:

public-hoist-pattern[]=*plugin*

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

You may also exclude patterns from hoisting using !.

例如:

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

shamefully-hoist

  • 默认值: false
  • 类型:Boolean

By default, pnpm creates a semistrict node_modules, meaning dependencies have access to undeclared dependencies but modules outside of node_modules do not. 通过这种布局,生态系统中的大多数的包都可以正常工作。 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 模块设置

modules-dir

  • Default: node_modules
  • 类型:路径

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

node-linker

  • Default: isolated
  • Type: isolated, hoisted, pnp

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

  • isolated - dependencies are symlinked from a virtual store at node_modules/.pnpm.
  • hoisted - a flat node_modules without symlinks is created. Same as the node_modules created by npm or Yarn Classic. 当使用此设置时,Yarn 的一个库用于提升。 使用此设置的正当理由:
    1. 你的工具无法很好地与符号链接配合使用。 A React Native project will most probably only work if you use a hoisted node_modules.
    2. 你的项目会被部署到 serverless 服务提供商。 一些 serverless 提供商(例如 AWS Lambda)不支持符号链接。 此问题的另一种解决方案是在部署之前打包你的应用程序。
    3. If you want to publish your package with "bundledDependencies".
    4. If you are running Node.js with the --preserve-symlinks flag.
  • 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
  • 类型:Boolean

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
  • 类型:Boolean

When false, pnpm will not write any files to the modules directory (node_modules). 这对于在用户空间的文件系统 (FUSE) 中挂载模块目录时很有用。 There is an experimental CLI that allows you to mount a modules directory with FUSE: @pnpm/mount-modules.

virtual-store-dir

  • Default: node_modules/.pnpm
  • Types: path

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

这是一个有用的设置,可以解决 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).

Or you can set the virtual store to .pnpm and add it to .gitignore. 这将使堆栈跟踪更清晰,因为依赖项的路径将会提高一个目录层级。

NOTE: the virtual store cannot be shared between several projects. 每个项目都应该有自己的虚拟存储(除了在工作空间中被共享的根目录)。

virtual-store-dir-max-length

  • 默认值:
    • On Linux/macOS: 120
    • On Windows: 60
  • Types: number

Sets the maximum allowed length of directory names inside the virtual store directory (node_modules/.pnpm). 如果你在 Windows 上遇到长路径问题,你可以将其设置为较低的数字。

package-import-method

  • 默认值: auto
  • Type: auto, hardlink, copy, clone, clone-or-copy

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 - try to clone packages from the store. 如果不支持克隆则从存储硬链接包。 如果克隆和链接都不支持,则回退到复制
  • hardlink - hard link packages from the store
  • clone-or-copy - try to clone packages from the store. 如果不支持克隆则回退到复制。
  • copy - copy packages from the store
  • clone - clone (AKA copy-on-write or reference link) packages from the store

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

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

modules-cache-max-age

  • Default: 10080 (7 days in minutes)
  • Type: number

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

dlx-cache-max-age

  • Default: 1440 (1 day in minutes)
  • Type: number

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

存储设置

store-dir

  • 默认值:
    • If the $PNPM_HOME env variable is set, then $PNPM_HOME/store
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/store
    • On Windows: ~/AppData/Local/pnpm/store
    • On macOS: ~/Library/pnpm/store
    • On Linux: ~/.local/share/pnpm/store
  • 类型:路径

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

该存储应始终位于进行安装的同一磁盘上,因此每个磁盘将有一个存储。 如果在使用磁盘中具有主目录,存储目录就会创建在这里。 如果磁盘上没有主目录,那么将在文件系统的根目录中创建该存储。 For example, if installation is happening on a filesystem mounted at /mnt, then the store will be created at /mnt/.pnpm-store. Windows 系统上也是如此。

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

verify-store-integrity

  • 默认值:true
  • 类型:Boolean

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

警告

已弃用的功能

  • 默认值: false
  • 类型:Boolean

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

strict-store-pkg-content-check

  • 默认值:true
  • 类型:Boolean

一些注册源允许以不同的包名或版本,发布完全相同的内容。 这破坏了存储中包的有效性检查。 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

  • 默认值:true
  • 类型:Boolean

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

prefer-frozen-lockfile

  • 默认值:true
  • 类型:Boolean

When set to true and the available pnpm-lock.yaml satisfies the package.json dependencies directive, a headless installation is performed. 无头安装会跳过所有依赖项解析,因为它不需要修改锁文件。

lockfile-include-tarball-url

  • 默认值: false
  • 类型:Boolean

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

git-branch-lockfile

  • 默认值: false
  • 类型:Boolean

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
  • Type: Array or null

此配置匹配当前分支名称以确定是否合并所有 git 分支锁文件文件。 By default, you need to manually pass the --merge-git-branch-lockfiles command line parameter. 这项配置允许自动完成这个过程。

例如:

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

You may also exclude patterns using !.

peers-suffix-max-length

  • Default: 1000
  • Type: number

添加到锁文件中的依赖项键的 peer ID 后缀的最大长度。 如果后缀较长,则用井号替换。

Registry & Authentication Settings

registry

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

&lt;scope>:registry

应用于指定范围的包的 npm 注册源。 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.

&lt;URL&gt;:_authToken

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

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

您还可以使用环境变量。 示例:

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

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 

&lt;URL&gt;:tokenHelper

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

助手路径的配置必须是绝对路径,并且没有参数。 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.

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

tokenHelper=/home/ivan/token-generator

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

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

请求设置

ca

  • Default: The npm CA certificate
  • Type: String, Array or null

可信的用于注册源 SSL 链接的 CA 签名证书。 值应采用 PEM 格式(也称 “Base-64 encoded X.509 (.CER)”)。 示例:

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

设置为 null 时仅允许已知注册商,若指定 CA 证书将只信任指定的证书颁发机构。

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

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

See also the strict-ssl config.

cafile

  • 默认值: null
  • 类型:路径

包含一个或多个 CA 证书的文件路径。 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.

&lt;URL&gt;:cafile

Define the path to a Certificate Authority file to use when accessing the specified registry. 示例:

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

cert

  • 默认值: null
  • Type: String

访问注册源时传递的客户端证书。 值应为 PEM 格式(也称 "Base-64 encoded X.509 (.CER)")。 示例:

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

It is not the path to a certificate file.

&lt;URL&gt;:certfile

Define the path to a certificate file to use when accessing the specified registry. 示例:

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

key

  • 默认值: null
  • Type: String

访问注册源时要传递的客户端密钥。 值应为 PEM 格式(也称 "Base-64 encoded X.509 (.CER)")。 示例:

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

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

此设置包含敏感信息。 Don't write it to a local .npmrc file committed to the repository.

&lt;URL&gt;:keyfile

Define the path to a client key file to use when accessing the specified registry. 示例:

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

git-shallow-hosts

  • Default: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
  • Type: string[]

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

https-proxy

  • 默认值: null
  • Type: url

用于传输 HTTPS 请求的代理。 If the HTTPS_PROXY, https_proxy, HTTP_PROXY or http_proxy environment variables are set, their values will be used instead.

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

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
  • Type: url

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

local-address

  • Default: undefined
  • Type: IP Address

连接到 npm 源时要使用的本地接口 IP 地址。

maxsockets

  • Default: network-concurrency x 3
  • 类型:Number

每个注册源(由协议/主机/端口号组合而成)允许的最大连接数。

noproxy

  • 默认值: null
  • Type: String

一个由逗号分割的域名字符串,表示不应该被使用的代理

strict-ssl

  • 默认值:true
  • 类型:Boolean

通过 HTTPS 向源发出请求时是否进行 SSL 密钥验证。

See also the ca option.

network-concurrency

  • Default: 16
  • 类型:Number

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

fetch-retries

  • Default: 2
  • 类型:Number

pnpm 无法从注册源中获取时的重试次数。

fetch-retry-factor

  • Default: 10
  • 类型:Number

重试回退的指数因子。

fetch-retry-mintimeout

  • Default: 10000 (10 seconds)
  • 类型:Number

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

fetch-retry-maxtimeout

  • Default: 60000 (1 minute)
  • 类型:Number

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

fetch-timeout

  • Default: 60000 (1 minute)
  • 类型:Number

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

Peer Dependency 设置

auto-install-peers

  • 默认值:true
  • 类型:Boolean

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

版本冲突

如果来自不同软件包的对等依赖项的需求版本存在冲突,那么 pnpm 将不会自动安装任何版本的冲突的对等依赖项。 相反,会输出一条警告信息。 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.

解决冲突

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

dedupe-peer-dependents

  • 默认值:true
  • 类型:Boolean

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

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

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)

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
  • 类型:Boolean

如果启用了此选项,那么在依赖树中存在缺失或无效的对等依赖关系时,命令将执行失败。

resolve-peers-from-workspace-root

  • 默认值:true
  • 类型:Boolean

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

命令行设置

[no-]color

  • 默认值: auto
  • Type: auto, always, never

设置输出的颜色.

  • auto - output uses colors when the standard output is a terminal or TTY.
  • 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. 大多数情况下只需要默认设置。
  • never - turns off colors. This is the setting used by --no-color.

loglevel

  • Default: info
  • Type: debug, info, warn, error

将显示等于或高于给定级别的任何日志。 You can instead pass --silent to turn off all output logs.

use-beta-cli

  • 默认值: false
  • 类型:Boolean

启用 CLI 测试版功能的实验性选项。 这意味着你使用的 CLI 功能可能会有一些不兼容的更改或潜在错误的更改。

recursive-install

  • 默认值:true
  • 类型:Boolean

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.

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

engine-strict

  • 默认值: false
  • 类型:Boolean

如果启用该选项,pnpm 将不安装任何声明与当前 Node 版本不兼容的包。

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

npm-path

  • 类型:路径

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

package-manager-strict

  • 默认值:true
  • 类型:Boolean

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.

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

package-manager-strict-version

  • 默认值: false
  • 类型:Boolean

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

  • 默认值:true
  • 类型:Boolean

When enabled, pnpm will automatically download and run the version of pnpm specified in the packageManager field of package.json. 这与 Corepack 使用的字段相同。 示例:

{
"packageManager": "pnpm@9.3.0"
}

构建设置

ignore-scripts

  • 默认值: false
  • 类型:Boolean

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

注意

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

ignore-dep-scripts

  • 默认值: false
  • 类型:Boolean

不执行已安装的包的任何脚本。 当前项目的 scripts 会执行

child-concurrency

  • Default: 5
  • 类型:Number

为并行构建 node_modules 分配的最大子进程数。

side-effects-cache

  • 默认值:true
  • 类型:Boolean

使用并缓存 (pre/post)install 钩子的结果。

side-effects-cache-readonly

  • 默认值: false
  • 类型:Boolean

仅在副作用缓存存在时使用,不要为新包创建它。

unsafe-perm

  • Default: false IF running as root, ELSE true
  • 类型:Boolean

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

node-options

  • Default: NULL
  • Type: String

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.

verify-deps-before-run

  • Default: false
  • Type: install, warn, error, prompt, false

This setting allows the checking of the state of dependencies before running scripts. The check runs on pnpm run and pnpm exec commands. The following values are supported:

  • install - Automatically runs install if node_modules is not up to date.
  • warn - Prints a warning if node_modules is not up to date.
  • prompt - Prompts the user for permission to run install if node_modules is not up to date.
  • error - Throws an error if node_modules is not up to date.
  • false - Disables dependency checks.

Node.js 设置

use-node-version

  • Default: undefined
  • Type: semver

指定应用于项目运行时的确切 Node.js 版本。 pnpm will automatically install the specified version of Node.js and use it for running pnpm run commands or the pnpm node command.

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

16.16.0

Use this .npmrc file:

use-node-version=16.16.0

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

  • Default: the value returned by node -v, without the v prefix
  • Type: semver

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

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 的新依赖项。

node-mirror:&lt;releaseDir>

  • Default: https://nodejs.org/download/<releaseDir>/
  • Type: URL

设置用于下载 Node.js 的基本 URL。 The <releaseDir> portion of this setting can be any directory from https://nodejs.org/download: release, rc, nightly, v8-canary, etc.

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

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/

工作空间设置

  • 默认值: false
  • Type: true, false, deep

If this is enabled, locally available packages are linked to node_modules instead of being downloaded from the registry. 这在 monorepo 中非常方便。 If you need local packages to also be linked to subdependencies, you can use the deep setting.

否则,将从注册源下载并安装软件包。 However, workspace packages can still be linked by using the workspace: range protocol.

prefer-workspace-packages

  • 默认值: false
  • 类型:Boolean

若启用了该选项,位于工作区的本地包将优先于注册表中的包,即使注册表中有存在更新的包。

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

shared-workspace-lockfile

  • 默认值:true
  • 类型:Boolean

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).

此选项的好处:

  • 每个依赖都是一个单例
  • 在 monorepo 中的安装更快
  • 代码更改都在一个文件中、代码审查(Cr )减少
注意

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. 这是前面提到的符号链接的结果。

save-workspace-protocol

  • Default: rolling
  • Type: true, false, rolling

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

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-prefixspec
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
  • 类型:Boolean

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

ignore-workspace-cycles

  • 默认值: false
  • 类型:Boolean

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

disallow-workspace-cycles

  • 默认值: false
  • 类型:Boolean

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

其它设置

save-prefix

  • Default: '^'
  • Type: '^', '~', ''

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

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.

当添加的包具有指定的范围时,将忽略此设置。 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

  • Default: latest
  • Type: String

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.

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

  • 默认值:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm/global
    • On Windows: ~/AppData/Local/pnpm/global
    • On macOS: ~/Library/pnpm/global
    • On Linux: ~/.local/share/pnpm/global
  • 类型:路径

指定储存全局依赖的目录。

global-bin-dir

  • 默认值:
    • If the $XDG_DATA_HOME env variable is set, then $XDG_DATA_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm
    • On macOS: ~/Library/pnpm
    • On Linux: ~/.local/share/pnpm
  • 类型:路径

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

state-dir

  • 默认值:
    • If the $XDG_STATE_HOME env variable is set, then $XDG_STATE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-state
    • On macOS: ~/.pnpm-state
    • On Linux: ~/.local/state/pnpm
  • 类型:路径

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

cache-dir

  • 默认值:
    • If the $XDG_CACHE_HOME env variable is set, then $XDG_CACHE_HOME/pnpm
    • On Windows: ~/AppData/Local/pnpm-cache
    • On macOS: ~/Library/Caches/pnpm
    • On Linux: ~/.cache/pnpm
  • 类型:路径

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

use-stderr

  • 默认值: false
  • 类型:Boolean

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

update-notifier

  • 默认值:true
  • 类型:Boolean

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

prefer-symlinked-executables

  • Default: true, when node-linker is set to hoisted and the system is POSIX
  • 类型:Boolean

Create symlinks to executables in node_modules/.bin instead of command shims. 在 Windows 上,此设置将被忽略,因为只有命令 shims 起作用。

ignore-compatibility-db

  • 默认值: false
  • 类型:Boolean

在安装过程中,某些包的依赖关系会被自动打补丁。 If you want to disable this, set this config to false.

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

resolution-mode

  • Default: highest (was lowest-direct from v8.0.0 to v8.6.12)
  • Type: highest, time-based, lowest-direct

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

  1. 直接依赖项将解析为最低版本。 So if there is foo@^1.1.0 in the dependencies, then 1.1.0 will be installed.
  2. 子依赖项将被解析的版本,是解析到最后一个直接依赖项发布的版本。

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

This resolution mode works only with npm's full metadata. 因此,在某些场景中,速度较慢。 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.

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

registry-supports-time-field

  • 默认值: false
  • 类型:Boolean

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
  • 类型:Boolean

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

deploy-all-files

  • 默认值: false
  • 类型:Boolean

在部署包或安装本地包时,包的所有文件都会被复制。 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
  • 类型:Boolean

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
  • 类型:Boolean

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.