Skip to main content
Version: 10.x

pnpm CLI

与 npm 的差异

🌐 Differences vs npm

与 npm 不同,pnpm 会验证所有选项。例如,pnpm install --target_arch x64 会失败,因为 --target_arch 不是 pnpm install 的有效选项。

🌐 Unlike npm, pnpm validates all options. For example, pnpm install --target_arch x64 will fail as --target_arch is not a valid option for pnpm install.

然而,一些依赖可能会使用 npm_config_ 环境变量,该变量是从命令行选项中生成的。在这种情况下,你有以下几种选择:

🌐 However, some dependencies may use the npm_config_ environment variable, which is populated from the CLI options. In this case, you have the following options:

  1. 显式设置环境变量:npm_config_target_arch=x64 pnpm install
  2. 使用 --config. 强制未知选项:pnpm install --config.target_arch=x64

选项

🌐 Options

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

以好像 pnpm 是在 <path> 而不是当前工作目录启动的方式运行。

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

-w, --workspace-root

运行时,就好像 pnpm 是在 workspace 的根目录下启动的,而不是当前工作目录。

🌐 Run as if pnpm was started in the root of the workspace instead of the current working directory.

命令

🌐 Commands

有关更多信息,请参阅各个 CLI 命令的文档。以下是一些方便的 npm 等效命令,帮助你入门:

🌐 For more information, see the documentation for individual CLI commands. Here is a list of handy npm equivalents to get you started:

npm 命令pnpm 等价命令
npm installpnpm install
npm i <pkg>pnpm add <pkg>
npm run <cmd>pnpm <cmd>

当使用未知命令时,pnpm 会搜索具有给定名称的脚本,因此 pnpm run lintpnpm lint 相同。如果没有具有指定名称的脚本,那么 pnpm 将把该命令作为 shell 脚本执行,因此你可以执行类似 pnpm eslint 的操作(参见 pnpm exec)。

🌐 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

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

🌐 Some environment variables that are not pnpm related might change the behaviour of pnpm:

这些环境变量可能会影响 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.