跳至主要內容
版本: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

Options

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

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.