跳到主内容
版本:9.x

pnpm CLI

与 npm 的差别

与 npm 不同的是,pnpm 会校验所有的参数。 For example, pnpm install --target_arch x64 will fail as --target_arch is not a valid option for pnpm install.

However, some dependencies may use the npm_config_ environment variable, which is populated from the CLI options. 在这种情况下,你有以下选择:

  1. explicitly set the env variable: npm_config_target_arch=x64 pnpm install
  2. force the unknown option with --config.: pnpm install --config.target_arch=x64

配置项

-C <path>, --dir <path>

Run as if pnpm was started in <path> instead of the current working directory.

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

环境变量

一些与 pnpm 无关的环境变量可能会改变 pnpm 的行为:

这些环境变量可能会影响 pnpm 将使用哪些目录来存储全局信息:

  • XDG_CACHE_HOME
  • XDG_CONFIG_HOME
  • XDG_DATA_HOME
  • XDG_STATE_HOME

您可以搜索文档来找到这些环境变量的设置。