pnpm CLI
短别名#
添加于:v11.0.0
pn 是 pnpm 的简称别名,而 pnx 是 pnpm dlx 的简称别名。你可以在任何需要使用 pnpm 或 pnpx 的地方使用它们:
pn install
pn add express
pn build
pn test
pnx create-vue my-app
与 npm 的差别#
与 npm 不同,pnpm 会校验所有选项。例如, pnpm install --target_arch x64 将失败,因为 --target_arch 不是 pnpm install 的有效选项。
Some dependencies read an npm_config_ environment variable during their build.
pnpm does not set these variables from its options, so set the variable yourself:
npm_config_target_arch=x64 pnpm install.
配置项#
-C <path>, --dir <path>#
在 <path> 的目录中启动 pnpm,而不是当前的工作目录。
-w, --workspace-root#
运行起来就好像 pnpm 是在 工作空间 的根目录中启动的,而不是在当前工作目录中启动的。
命令#
有关更多信息,请参阅各个 CLI 命令的文档。以下是简便的 npm 命令等效列表,可帮助你入门:
| npm 命令 | pnpm 等效 |
|---|---|
npm install |
pnpm install |
npm i <pkg> |
pnpm add <pkg> |
npm run <cmd> |
pnpm <cmd> |
npx <pkg> |
pnx <pkg> |
当使用未知命令时,pnpm 将搜索具有给定名称的脚本,因此 pnpm run lint 与 pnpm lint 相同。如果没有具有指定名称的脚本,
那么 pnpm 将以 shell 脚本的形式执行该命令,因此你可以执行类似 pnpm eslint 的操作(参见 pnpm exec)。
Since v11.28.0, this also works with --filter and --recursive: pnpm -r eslint runs the eslint script in the selected projects that have one, and when none of them has a script by that name, it runs the eslint command installed in their dependencies. pnpm run with --filter or -r still reports the missing script.
环境变量#
一些与 pnpm 无关的环境变量可能会改变 pnpm 的行为:
这些环境变量可能会影响 pnpm 将使用哪些目录来存储全局信息:
XDG_CACHE_HOMEXDG_CONFIG_HOMEXDG_DATA_HOMEXDG_STATE_HOME
You can search the docs to find the settings that use these environment variables.