pnpm CLI
与 npm 的差异
与 npm 不同,pnpm 会验证所有参数。例如,pnpm install --target_arch x64
将运行
失败,由于 --target_arch
不是一个有效的 pnpm install
参数。
但是,某些依赖项可能会使用以 npm_config_
开头的环境变量,该环境变量
是可以通过 CLI 参数添加的。在这种情况下,假定有如下参数:
- 直接设置环境变量:
npm_config_target_arch=x64 pnpm install
- 利用
--config.
前缀强制设置参数:pnpm install --config.target_arch=x64
参数
-C <path>, --dir <path>
将 <path>
设置为 pnpm 的运行目录,而不是当前目录。
-w, --workspace-root
Run as if pnpm was started in the root of the workspace instead of the current working directory.
命令
有关更多信息,请参见各个 CLI 命令的文档。以下 是一个与 npm 等价命令的对照表,帮助你快速入门:
npm 命令 | pnpm 等价命令 |
---|---|
npm install | pnpm install |
npm i <pkg> | pnpm add <pkg> |
npm run <cmd> | pnpm <cmd> |
When an unknown command is used, pnpm will search for a script with the given name,
so pnpm run lint
is the same as pnpm lint
. If there is no script with the specified name,
then pnpm will execute the command as a shell script, so you can do things like pnpm eslint
(see pnpm exec
).
Environment variables
Some environment variables that are not pnpm related might change the behaviour of pnpm:
These environment variables may influence what directories pnpm will use for storing global information:
XDG_CACHE_HOME
XDG_CONFIG_HOME
XDG_DATA_HOME
XDG_STATE_HOME
You can search the docs to find the settings that leverage these environment variables.