设置(pnpm-workspace.yaml)
pnpm 从命令行、环境变量和 pnpm-workspace.yaml 获取配置。
仅从 .npmrc 文件中读取身份验证和注册表设置。 所有其他设置(例如 hoistPattern、nodeLinker、shamefullyHoist 等) 必须在 pnpm-workspace.yaml 或全局的 ~/.config/pnpm/config.yaml 中进行配置。
pnpm config 命令可用于读取和编辑项目和全局配置文件的内容。
相关配置文件为:
- 项目配置文件:
/path/to/my/project/pnpm-workspace.yaml - 全局配置文件
授权相关的设置通过 .npmrc 处理。
配置文件中的值可能包含使用 ${NAME} 语法的环境变量。 也可以使用默认值指定环境变量。 使用 ${NAME-fallback} 将在未设置 NAME 时返回 fallback。 ${NAME:-fallback} ,会在 NAME 不存在或为空字符串时返回 fallback 。
Since v11.5.3, env variables are not expanded in settings of pnpm-workspace.yaml that define registry URLs: registry and the URL values of registries and namedRegistries. 在这些设置中,包含 ${...} 占位符的值会被忽略。 由于 pnpm-workspace.yaml 会被提交到仓库中,如果注册源 URL 中包含可展开的环境变量,恶意仓库可能会利用这一点,将环境中的敏感信息泄露给攻击者控制的注册源。 改为在受信任的位置配置动态注册源 URL:全局配置文件或 CLI 选项。
packages
Besides settings, pnpm-workspace.yaml defines the root of the workspace and
enables you to include / exclude directories from the workspace. If the
packages field is omitted, only the root package is included in the workspace.
例如:
packages:
# 指定根目录直接子目录中的包
- 'my-app'
# packages/ 直接子目录中的所有包
- 'packages/*'
# components/ 子目录中的所有包
- 'components/**'
# 排除测试目录中的包
- '!**/test/**'
即使使用了自定义目录位置通配符,根软件包也总是被包含.
目录也在 pnpm-workspace.yaml 文件中定义。 有关详细信息,请参阅 Catalogs。
packages:
- 'packages/*'
catalog:
chalk: ^4.1.2
catalogs:
react16:
react: ^16.7.0
react-dom: ^16.7.0
react17:
react: ^17.10.0
react-dom: ^17.10.0
packageConfigs
添加于:v11.0.0
允许为各个工作区包设置项目特定的配置。 这将替换工作区项目特定的 .npmrc 文件。
packageConfigs 可以指定为包名称到配置对象的映射:
packages:
- "packages/project-1"
- "packages/project-2"
packageConfigs:
"project-1":
saveExact: true
"project-2":
savePrefix: "~"
或者作为模式匹配规则的数组:
packages:
- "packages/project-1"
- "packages/project-2"
packageConfigs:
- match: ["project-1", "project-2"]
modulesDir: "node_modules"
saveExact: true
设置
Every setting is listed below, grouped by topic. Follow a setting to read its documentation, or open the full reference of a group.
依赖解析
- overrides
- packageExtensions
- allowedDeprecatedVersions
- update
- supportedArchitectures
- ignoredOptionalDependencies
- minimumReleaseAge
- minimumReleaseAgeExclude
- minimumReleaseAgeIgnoreMissingTime
- minimumReleaseAgeStrict
- trustPolicy
- trustPolicyExclude
- trustPolicyIgnoreAfter
- trustLockfile
- blockExoticSubdeps
- registries
- namedRegistries
Node 模块设置
- modulesDir
- nodeLinker
- nodeExperimentalPackageMap
- nodePackageMapType
- symlink
- enableModulesDir
- virtualStoreDir
- virtualStoreDirMaxLength
- virtualStoreOnly
- packageImportMethod
- modulesCacheMaxAge
- dlxCacheMaxAge
- enableGlobalVirtualStore
依赖提升设置
存储设置
锁文件设置
- lockfile
- preferFrozenLockfile
- lockfileIncludeTarballUrl
- gitBranchLockfile
- mergeGitBranchLockfilesBranchPattern
- peersSuffixMaxLength
网络设置
请求设置
- gitShallowHosts
- networkConcurrency
- fetchRetries
- fetchRetryFactor
- fetchRetryMintimeout
- fetchRetryMaxtimeout
- fetchTimeout
- fetchWarnTimeoutMs
- fetchMinSpeedKiBps
对等依赖设置
- autoInstallPeers
- dedupePeerDependents
- dedupePeers
- strictPeerDependencies
- resolvePeersFromWorkspaceRoot
- peerDependencyRules
命令行设置
- [no-]color
- loglevel
- useBetaCli
- recursiveInstall
- engineStrict
- npmPath
- pmOnFail
- ignoreWorkspaceRootCheck
Node.js 设置
构建设置
- ignoreScripts
- childConcurrency
- sideEffectsCache
- sideEffectsCacheReadonly
- unsafePerm
- nodeOptions
- verifyDepsBeforeRun
- strictDepBuilds
- allowBuilds
- dangerouslyAllowAllBuilds
Versioning Settings
- versioning.fixed
- versioning.ignore
- versioning.maxBump
- versioning.lanes
- versioning.epics
- versioning.changelog.storage
其它设置
- savePrefix
- tag
- globalDir
- globalBinDir
- npmrcAuthFile
- stateDir
- cacheDir
- useStderr
- updateNotifier
- preferSymlinkedExecutables
- ignoreCompatibilityDb
- resolutionMode
- registrySupportsTimeField
- extendNodePath
- deployAllFiles
- dedupeDirectDeps
- optimisticRepeatInstall
- requiredScripts
- enablePrePostScripts
- scriptShell
- shellEmulator
- catalogMode
- ci
- cleanupUnusedCatalogs
Workspace Settings
These settings are configured in pnpm-workspace.yaml as well, but are documented together with the workspace feature they belong to.
- linkWorkspacePackages
- injectWorkspacePackages
- dedupeInjectedDeps
- syncInjectedDepsAfterScripts
- preferWorkspacePackages
- sharedWorkspaceLockfile
- saveWorkspaceProtocol
- includeWorkspaceRoot
- ignoreWorkspaceCycles
- disallowWorkspaceCycles
- failIfNoMatch
Settings documented elsewhere
- patchedDependencies
- pnpmfile, globalPnpmfile and ignorePnpmfile
- Authorization settings, which are read from
.npmrc