跳到主内容
版本:7.x

.npmrc

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

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

四个相关文件分别为:

  • 每个项目的配置文件(/path/to/my/project/.npmrc
  • 每个工作区的配置文件(包含 pnpm-workspace.yaml 文件的目录)
  • 每位用户的配置文件( ~/.npmrc
  • 全局配置文件( /etc/npmrc

所有 .npmrc 文件都遵循 INI-formatted 列表,包含 key = value 参数。

依赖提升设置

hoist

  • 默认值: true
  • 类型: boolean

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

hoist-pattern

  • 默认值: ['*']
  • 类型: string[]

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

例如:

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

从 v7.12.0 开始, 你可以使用 ! pattern 排除提升。

例如:

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

public-hoist-pattern

  • 默认值: ['*eslint*', '*prettier*']
  • 类型: string[]

不同于 hoist-pattern 会把依赖提升到一个虚拟存储中的隐藏的模块目录中,public-hoist-pattern 将匹配的依赖提升至根模块目录中。 提升至根模块目录中意味着应用代码可以访问到幻影依赖,即使他们对解析策略做了不当的修改。

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

例如:

public-hoist-pattern[]=*plugin*

注意:设置 shamefully-hoisttrue 与设置 public-hoist-pattern* 是一样的。

从 v7.12.0 开始, 你可以使用 ! pattern 排除提升。

例如:

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

shamefully-hoist

  • 默认值: false
  • 类型:Boolean

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

Node 模块设置

store-dir

  • 默认值:
    • If the $PNPM_HOME env variable is set, then $PNPM_HOME/store
    • 如果设置了 $XDG_DATA_HOME 环境变量,则为 $XDG_DATA_HOME/pnpm/store
    • 在 Windows 上: ~/AppData/Local/pnpm/store
    • 在 macOS 上: ~/Library/pnpm/store
    • 在 Linux 上: ~/.local/share/pnpm/store
  • 类型:path

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

该存储应始终位于进行安装的同一磁盘上,因此每个磁盘将有一个存储。 如果在使用磁盘中具有主目录,存储目录就会创建在这里。 如果磁盘上没有主目录,那么将在文件系统的根目录中创建该存储。 例如,如果安装发生在挂载在 /mnt 的文件系统上,那么存储将在 /mnt/.pnpm-store 处创建。 Windows 系统上也是如此。

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

modules-dir

  • 默认值:node_modules
  • 类型:path

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

node-linker

  • 默认值:isolated
  • 类型: isolated, hoisted, pnp

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

  • isolated - 依赖项从虚拟存储 node_modules/.pnpm 中建立符号链接
  • hoisted - 创建一个没有符号链接的扁平的 node_modules。 与 npm 或 Yarn Classic 创建 node_modules 一致。 当使用此设置时,Yarn 的一个库用于提升。 使用此设置的正当理由:
    1. 您的工具不适用于符号链接。 React Native 项目很可能只有在你使用提升的 node_modules 才能工作。
    2. 您的项目会被部署到 serverless 服务提供商。 一些 serverless 提供商(例如 AWS Lambda)不支持符号链接。 此问题的另一种解决方案是在部署之前打包您的应用程序。
    3. 如果你想用 "bundledDependencies" 发布你的包。
    4. 如果您使用 --preserve-symlinks 标志运行 Node.js。
  • pnp - 没有 node_modules。 Plug'n'Play 是一种 Yarn Berry 使用的创新的 Node 依赖策略。 当使用 pnp 作为您的链接器时,建议同时将 symlink 设置为 false
  • 默认值: true
  • 类型:Boolean

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

enable-modules-dir

  • 默认值: true
  • 类型:Boolean

false 时,pnpm 不会将任何文件写入模块目录(node_modules)。 这对于在用户空间的文件系统 (FUSE) 中挂载模块目录时很有用。 有一个实验性 CLI 允许您在 FUSE 中挂载模块目录:@pnpm/mount-modules

virtual-store-dir

  • 默认值:node_modules/.pnpm
  • 类型:path

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

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

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

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

package-import-method

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

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

  • auto - 尝试从存储克隆包。 如果不支持克隆则从存储硬链接包。 如果克隆和链接都不支持,则回退到复制
  • hardlink - 从存储硬链接包
  • clone-or-copy - 尝试从存储中克隆包。 如果不支持克隆则回退到复制。
  • copy - 从存储中复制包
  • clone - 从存储中克隆(也称为 copy-on-write 或参考链接)包

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

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

提示

尽管 macOS 支持克隆,但目前 Node.js 中存在错误 该错误阻止我们在 pnpm 中使用它。 如果您有解决方法的想法,请 到来帮助我们

modules-cache-max-age

  • 默认值: 10080 (以分钟为单位的 7 天)
  • 类型:number

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

锁文件设置

lockfile

  • 默认值: true
  • 类型:Boolean

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

prefer-frozen-lockfile

  • 默认值: true
  • 类型:Boolean

当设置为 true 并且存在 pnpm-lock.yaml 满足 package.json 中的依赖关系时,执行无头安装。 无头安装会跳过所有依赖项解析,因为它不需要修改lockfile。

lockfile-include-tarball-url

添加于:v7.6.0

  • 默认值: false
  • 类型:Boolean

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

git-branch-lockfile

Added in: v7.3.0

  • 默认值: false
  • 类型:Boolean

如果设置为 true,那么在安装后生成的 lockfile 名称将基于当前分支名称命名,以完全避免合并冲突。 例如,如果当前分支名称为 feature-foo,则 对应的 lockfile 名称将为 pnpm-lock.feature-foo.yaml 而不是 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

Added in: v7.3.0

  • Default: null
  • Type: Array or null

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.

例如:

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

You may also exclude patterns using !.

use-lockfile-v6

Added in: v7.24.0

  • 默认值: false
  • 类型:Boolean

Use the new v6 lockfile format, which will be the default one in pnpm v8. This new format is more readable as it doesn't use hashes to shorten long dependency paths.

注册源 & 身份验证设置

registry

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

<scope>:registry

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. 示例:

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

You may also use an environment variable. 示例:

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

或者,您可以直接使用环境变量,而不更改 .npmrc:

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

<URL>:tokenHelper

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.

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

请求设置

ca

  • 默认值:The npm CA certificate
  • 类型:String,Array 或 null

为与源服务器进行可信的 SSL 链接颁发的 CA 证书。 值应采用 PEM 格式(也称 “Base-64 encoded X.509 (.CER)”)。 示例:

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

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

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

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

更多信息可见 strict-ssl 设置

cafile

  • Default: null
  • 类型:path

包含一个或多个 CA 证书的文件路径。 类似于 ca 设置,但允许将一个或多个 CA 信息存储在文件中,而不是通过命令行指定。

cert

  • Default: null
  • 类型:String

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

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

它不是证书文件的路径(也没有 certfile 选项)。

key

  • Default: null
  • 类型:String

访问注册源时要传递的客户端密钥。 值应采用 PEM 格式(AKA “Base-64 encoded X.509 (.CER)”)。 示例:

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

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

这个设置含有敏感信息! 不要将其写入本地会提交到仓库的 .npmrc 文件。

git-shallow-hosts

  • 默认值: ['github.com', 'gist.github.com', 'gitlab.com', 'bitbucket.com', 'bitbucket.org']
  • 类型: string[]

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

https-proxy

  • Default: null
  • 类型:url

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

If your proxy URL contains a username and password, make sure to URL-encode them. 例如:

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

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

http-proxy

proxy

  • Default: null
  • 类型:url

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

local-address

  • 默认值:undefined
  • 类型:**IP Address **

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

maxsockets

  • 默认值:network-concurrency x 3
  • 类型:Number

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

noproxy

  • Default: null
  • 类型:String

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

strict-ssl

  • 默认值: true
  • 类型:Boolean

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

另请参阅 ca 配置项。

network-concurrency

  • 默认值:16
  • 类型:Number

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

fetch-retries

  • 默认值:2
  • 类型:Number

如果 pnpm 无法从registry中获取,重试次数。

fetch-retry-factor

  • 默认值:10
  • 类型:Number

重试回退的指数因子。

fetch-retry-mintimeout

  • 默认值:10000(10 秒)
  • 类型:Number

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

fetch-retry-maxtimeout

  • 默认值:60000(1 分钟)
  • 类型:Number

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

fetch-timeout

  • 默认值:60000(1 分钟)
  • 类型:Number

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

Peer Dependency 设置

auto-install-peers

  • 默认值: false
  • 类型:Boolean

当值为 true 时,将自动安装任何缺少的非可选同级依赖关系。

dedupe-peer-dependents

Added in: v7.29.0

  • 默认值: false
  • 类型: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

  • Default: false (was true from v7.0.0 until v7.13.5)
  • 类型:Boolean

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

resolve-peers-from-workspace-root

Added in: v7.23.0

  • 默认值: false
  • 类型:Boolean

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

命令行设置

[no-]color

  • 默认值:auto
  • 类型:auto, always, never

设置输出的颜色.

  • auto - 当标准输出是终端或 TTY 时,输出会带有颜色。
  • always - 忽略终端和 pipe 之间的区别。 你很少需要这个选项; 在大多数情况下,如果您想在重定向的输出中使用颜色代码,您可以将 --color 标志传递给 pnpm 命令以强制它输出颜色。 大多数情况下只需要默认设置。
  • never - 关闭颜色。 这是 --no-color 使用的设置。

loglevel

  • 默认值:info
  • 类型:debug, info, warn, error

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

use-beta-cli

  • 默认值: false
  • 类型:Boolean

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

recursive-install

  • 默认值: true
  • 类型:Boolean

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

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

engine-strict

  • 默认值: false
  • 类型:Boolean

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

但无论该属性设置成什么值,如果项目(不是依赖项)在其 engines 字段中指定了不兼容的版本,则安装将始终失败。

npm-path

  • 类型:path

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

构建设置

ignore-scripts

  • 默认值: false
  • 类型:Boolean

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

注意

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

ignore-dep-scripts

Added in: v7.9.0

  • 默认值: false
  • 类型:Boolean

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

child-concurrency

  • 默认值: 5
  • 类型:Number

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

side-effects-cache

  • 默认值: true
  • 类型:Boolean

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

side-effects-cache-readonly

  • 默认值: false
  • 类型:Boolean

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

unsafe-perm

  • 默认值:true, 如果以 root 身份运行则为 false
  • 类型:Boolean

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

Node.js 设置

use-node-version

  • 默认值:undefined
  • 类型:semver

指定应用于项目运行时的确切 Node.js 版本。 pnpm 将自动安装指定版本的 Node.js 并将其用于执行 pnpm run 命令或 pnpm node 命令。

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

16.16.0

使用这个 .npmrc 文件:

use-node-version=16.16.0

node-version

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

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

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

node-version=12.22.0
engine-strict=true

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

node-mirror:<releaseDir>

  • 默认值: https://nodejs.org/download/<releaseDir>/
  • 类型: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/

Workspace Settings

  • 默认值: true
  • 类型:true, false, 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. 如果您需要本地包也链接到子依赖项,您可以使用 deep 设置。

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

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

Advantages of this option:

  • 每个依赖都是一个单例
  • 在 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. This is a result of the aforementioned symbolic linking.

save-workspace-protocol

  • 默认值: true
  • 类型: true, false, rolling

这个设置控制从工作区中链接的 dependencies 如何添加至 package.json

如果 foo@1.0.0 在工作区中,在工作区的另一个项目中运行 pnpm add foo ,则 foo 会被按如下方式添加到依赖项字段。 save-prefix 设置也会影响 spec 的创建方式。

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

添加于:v7.4.0

  • 默认值: false
  • 类型:Boolean

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

其它设置

use-running-store-server

  • 默认值: false
  • 类型:Boolean

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

save-prefix

  • 默认值: '^'
  • 类型:String

配置软件包在 package.json 文件中的版本前缀。

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

当添加的包具有指定的范围时,将忽略此设置。 例如,pnpm add foo@2 将会把 package.json 中的 foo 设置为 2,而忽略 save-prefix 的值。

tag

  • 默认值: ** latest **
  • 类型:String

如果您执行 pnpm add 添加了一个包并且没有提供特定版本,那么它安装设置中这个标记下的版本。

如果 pnpm tag 命令没有给出明确的标签,这也会设置的标签添加到指定的 package@version

global-dir

  • 默认值:
    • 如果设置了 $XDG_DATA_HOME 环境变量,则为 $XDG_DATA_HOME/pnpm/store
    • 在 Windows 上:~/AppData/Local/pnpm/store
    • 在 macOS 上:~/Library/pnpm/global
    • 在 Linux 上:~/.local/share/pnpm/global
  • 类型:path

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

global-bin-dir

  • 默认值:
    • 如果设置了 $XDG_DATA_HOME 环境变量,则为 $XDG_DATA_HOME/pnpm
    • 在 Windows 上:~/AppData/Local/pnpm-cache
    • 在 macOS 上: ~/Library/pnpm/store
    • 在 Linux 上:~/.local/state/pnpm
  • 类型:path

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

state-dir

  • 默认值:
    • 如果设置了 $XDG_STATE_HOME 环境变量,则为 $XDG_STATE_HOME/pnpm
    • 在 Windows 上:~/AppData/Local/pnpm-state
    • 在 macOS 上:~/.pnpm-state
    • 在 Linux 上:~/.local/state/pnpm
  • 类型:path

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

cache-dir

  • 默认值:
    • 如果设置了 $XDG_CACHE_HOME 环境变量,则为 $XDG_CACHE_HOME/pnpm
    • 在 Windows 上:~/AppData/Local/pnpm-cache
    • 在 macOS 上:~/Library/Caches/pnpm
    • 在 Linux 上:~/.cache/pnpm
  • 类型:path

包元数据缓存的位置。

use-stderr

  • 默认值: false
  • 类型:Boolean

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

update-notifier

  • 默认值: true
  • 类型:Boolean

设置为 false 以便在使用较旧版本的 pnpm 时关闭更新通知。

prefer-symlinked-executables

添加于:v7.6.0

  • 默认值:当 node-linker 设置为 hoisted 且系统为POSIX时, 默认true
  • 类型:Boolean

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

verify-store-integrity

Added in: v7.7.0

  • 默认值: true
  • 类型:Boolean

默认情况下,如果存储中的文件已被修改,则在将其链接到项目的 node_modules之前会检查该文件的内容。 If verify-store-integrity is set to false, files in the content-addressable store will not be checked during installation.

ignore-compatibility-db

Added in: v7.9.0

  • 默认值: false
  • 类型:Boolean

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

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

resolution-mode

Added in: v7.10.0

  • Default: highest
  • Type: highest, time-based, lowest-direct (added in: v7.27.0)

resolution-mode 设置为 time-based,依赖关系将按以下方式解析:

  1. 直接依赖项将解析为最低版本。 因此,如果依赖项中有 foo@^1.1.0 ,则将安装 1.1.0
  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

Added in: v7.10.0

  • 默认值: 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

新增于:v7.25.0

  • 默认值: true
  • 类型:Boolean

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