pnpm config
别名:c
¥Aliases: c
管理配置文件。
¥Manage the configuration files.
配置文件的格式为 INI(全局)和 YAML(本地)。
¥The configuration files are in INI (the global) and YAML (the local) formats.
本地配置文件位于项目根目录下,名为 pnpm-workspace.yaml.conf。
¥The local configuration file is located in the root of the project and is named pnpm-workspace.yaml.
全局配置文件位于以下位置之一:
¥The global configuration file is located at one of the following locations:
-
如果设置了 $XDG_CONFIG_HOME 环境变量,则 $XDG_CONFIG_HOME/pnpm/rc
¥If the $XDG_CONFIG_HOME env variable is set, then $XDG_CONFIG_HOME/pnpm/rc
-
在 Windows 上:~/AppData/Local/pnpm/config/rc
¥On Windows: ~/AppData/Local/pnpm/config/rc
-
在 macOS 上:~/Library/Preferences/pnpm/rc
¥On macOS: ~/Library/Preferences/pnpm/rc
-
在 Linux 上:~/.config/pnpm/rc
¥On Linux: ~/.config/pnpm/rc
命令
¥Commands
set <key> <value>
将配置键设置为提供的值。
¥Set the config key to the value provided.
不使用 --json 标志时,它会将值解析为纯字符串:
¥Without the --json flag, it parses the value as plain string:
pnpm config set --location=project nodeVersion 22.0.0
使用 --json 标志时,它会将值解析为 JSON:
¥With the --json flag, it parses the value as JSON:
pnpm config set --location=project --json nodeVersion '"22.0.0"'
--json 标志还允许 pnpm config set 创建数组和对象:
¥The --json flag also allows pnpm config set to create arrays and objects:
pnpm config set --location=project --json onlyBuiltDependencies '["react", "react-dom"]'
pnpm config set --location=project --json catalog '{ "react": "19" }'
set 命令不接受属性路径。
¥The set command does not accept a property path.
get <key>
打印提供的密钥的配置值。
¥Print the config value for the provided key.
key 可以是一个简单的键:
¥The key can be a simple key:
pnpm config get nodeVersion
pnpm config get --json nodeVersion
pnpm config get --json packageExtensions
pnpm config get --json onlyBuiltDependencies
pnpm config get --json catalog
它也可以是属性路径:
¥It can also be a property path:
pnpm config get 'packageExtensions["@babel/parser"].peerDependencies["@babel/types"]'
pnpm config get --json 'packageExtensions["@babel/parser"].peerDependencies["@babel/types"]'
pnpm config get 'onlyBuiltDependencies[0]'
pnpm config get --json 'onlyBuiltDependencies[0]'
pnpm config get catalog.react
pnpm config get --json catalog.react
属性路径的语法模拟 JavaScript 属性路径。
¥The syntax of the property path emulates JavaScript property paths.
delete <key>
从配置文件中删除配置密钥。
¥Remove the config key from the config file.
list
显示所有配置设置。
¥Show all the config settings.
选项
¥Options
--global, -g
在全局配置文件中设置配置。
¥Set the configuration in the global config file.
--location
默认情况下,--location 设置为 global。
¥By default, --location is set to global.
当设置为 project 时,将使用最接近 package.json 处的 .npmrc 文件。如果目录中没有 .npmrc 文件,则该设置将写入 pnpm-workspace.yaml 文件。
¥When set to project, the .npmrc file at the nearest package.json will be used. If no .npmrc file is present in the directory, the setting will be written to a pnpm-workspace.yaml file.
当设置为 global 时,性能与设置 --global 选项相同。
¥When set to global, the performance is the same as setting the --global option.
--json
让 get 和 list 以 JSON 格式显示所有配置设置,并让 set 将值解析为 JSON。
¥Make get and list show all the config settings in JSON format and make set parse the value as JSON.