pnpm install
别名:i
🌐 Aliases: i
pnpm install 用于安装一个项目的所有依赖。
在持续集成(CI)环境中,如果存在锁文件但需要更新,安装将失败。
🌐 In a CI environment, installation fails if a lockfile is present but needs an update.
在 workspace 中,pnpm install 会在所有项目中安装所有依赖。如果你想禁用此行为,请将 recursive-install 设置为 false。
🌐 Inside a workspace, pnpm install installs all dependencies in all the
projects. If you want to disable this behavior, set the recursive-install
setting to false.
长话短说
🌐 TL;DR
| 命令 | 含义 |
|---|---|
pnpm i --offline | 仅从存储离线安装 |
pnpm i --frozen-lockfile | pnpm-lock.yaml 未更新 |
pnpm i --lockfile-only | 仅更新 pnpm-lock.yaml |
过滤依赖的选项
🌐 Options for filtering dependencies
没有锁文件时,pnpm 必须创建一个,并且它必须保持一致,无论依赖过滤如何,所以在没有锁文件的目录上运行 pnpm install --prod 仍然会解析开发依赖,如果解析失败则会报错。这个规则的唯一例外是 link: 依赖。
🌐 Without a lockfile, pnpm has to create one, and it must be consistent regardless of dependencies
filtering, so running pnpm install --prod on a directory without a lockfile would still resolve the
dev dependencies, and it would error if the resolution is unsuccessful. The only exception for this rule
are link: dependencies.
如果没有 --frozen-lockfile,pnpm 将检查来自 file: 依赖的过时信息,因此在目标 file: 已被移除的环境中运行没有 --frozen-lockfile 的 pnpm install --prod 将会出错。
🌐 Without --frozen-lockfile, pnpm will check for outdated information from file: dependencies, so
running pnpm install --prod without --frozen-lockfile on an environment where the target of file:
has been removed would error.
--prod, -P
- 默认:假
- 类型:布尔
如果 true,pnpm 将不会安装 devDependencies 中列出的任何包,并且会删除已安装的这些包。
如果 false,pnpm 将安装 devDependencies 和 dependencies 中列出的所有包。
🌐 If true, pnpm will not install any package listed in devDependencies and will remove
those insofar they were already installed.
If false, pnpm will install all packages listed in devDependencies and dependencies.
--dev, -D
只有 devDependencies 已安装,而 dependencies 已被移除,但前提是它们之前已经安装过。
🌐 Only devDependencies are installed and dependencies are removed insofar they
were already installed.
--no-optional
optionalDependencies 未安装。
选项
🌐 Options
--force
强制重新安装依赖:重新获取存储中已修改的包,重新创建由不兼容版本的 pnpm 创建的锁文件和/或模块目录。即使可选依赖不符合当前环境(CPU、操作系统、架构),也安装所有可选依赖。
🌐 Force reinstall dependencies: refetch packages modified in store, recreate a lockfile and/or modules directory created by a non-compatible version of pnpm. Install all optionalDependencies even they don't satisfy the current environment(cpu, os, arch).
--offline
- 默认:假
- 类型:布尔
如果 true,pnpm 将只使用存储中已有的包。如果本地找不到某个包,安装将失败。
🌐 If true, pnpm will use only packages already available in the store.
If a package won't be found locally, the installation will fail.
--prefer-offline
- 默认:假
- 类型:布尔
如果使用 true,缓存数据的陈旧检查将被跳过,但缺失的数据仍会从服务器请求。若要强制完全离线模式,请使用 --offline。
🌐 If true, staleness checks for cached data will be bypassed, but missing data
will be requested from the server. To force full offline mode, use --offline.
--no-lockfile
不要读取或生成 pnpm-lock.yaml 文件。
🌐 Don't read or generate a pnpm-lock.yaml file.
--lockfile-only
- 默认:假
- 类型:布尔
使用时,只会更新 pnpm-lock.yaml 和 package.json。不会写入 node_modules 目录。
🌐 When used, only updates pnpm-lock.yaml and package.json. Nothing gets written to the node_modules directory.
--fix-lockfile
自动修复损坏的锁定文件条目。
🌐 Fix broken lockfile entries automatically.
--frozen-lockfile
- 默认:
- 对于非CI:假
- 对于 CI:true,如果存在锁定文件
- 类型:布尔
如果 true,pnpm 不会生成 lockfile,并且如果 lockfile 与清单不同步 / 需要更新或不存在 lockfile 时,安装将失败。
🌐 If true, pnpm doesn't generate a lockfile and fails to install if the lockfile
is out of sync with the manifest / an update is needed or no lockfile is
present.
在 [CI 环境] 中,此设置默认是 true。以下代码用于检测 CI 环境:
🌐 This setting is true by default in CI environments. The following code is used to detect CI environments:
exports.isCI = !!(
env.CI || // Travis CI, CircleCI, Cirrus CI, GitLab CI, Appveyor, CodeShip, dsari
env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
env.BUILD_NUMBER || // Jenkins, TeamCity
env.RUN_ID || // TaskCluster, dsari
exports.name ||
false
)
--merge-git-branch-lockfiles
合并所有 git 分支锁定文件。 了解有关 git 分支锁定文件的更多信息。
🌐 Merge all git branch lockfiles. Read more about git branch lockfiles.
--reporter=<name>
- 默认:
- 对于 TTY stdout:默认
- 对于非 TTY 标准输出:仅追加
- 类型:默认、仅追加、ndjson、静默
允许你选择将在终端记录有关安装进度的调试信息的报告器。
🌐 Allows you to choose the reporter that will log debug info to the terminal about the installation progress.
- silent - 不会在控制台记录任何输出,甚至致命错误也不会显示
- 默认 - 当标准输出为 TTY 时使用的默认报告器
- 仅追加 - 输出总是附加到末尾。不会进行光标操作
- ndjson - 最详细的报告工具。以 ndjson 格式打印所有日志
如果你想更改打印的信息类型,请使用 loglevel 设置。
🌐 If you want to change what type of information is printed, use the loglevel setting.
--shamefully-hoist
- 默认:假
- 类型:布尔
创建一个扁平的 node_modules 结构,类似于 npm 或 yarn 的结构。
警告:强烈不建议这样做。
🌐 Creates a flat node_modules structure, similar to that of npm or yarn.
WARNING: This is highly discouraged.
--ignore-scripts
- 默认:假
- 类型:布尔
不要执行项目 package.json 及其依赖中定义的任何脚本。
🌐 Do not execute any scripts defined in the project package.json and its
dependencies.
--filter <package_selector>
--resolution-only
重复运行分辨率:有助于打印出同级依赖问题。
🌐 Re-runs resolution: useful for printing out peer dependency issues.
--cpu=<name>
新增于:v10.14.0
🌐 Added in: v10.14.0
覆盖本地模块的 CPU 架构以进行安装。可接受的值与来自 process.arch 的 package.json 的 cpu 字段相同。
🌐 Override CPU architecture of native modules to install. Acceptable values are same as cpu field of package.json, which comes from process.arch.
--os=<name>
新增于:v10.14.0
🌐 Added in: v10.14.0
覆盖本地模块的操作系统以进行安装。可接受的值与来自 process.platform 的 package.json 的 os 字段相同。
🌐 Override OS of native modules to install. Acceptable values are same as os field of package.json, which comes from process.platform.
--libc=<name>
新增于:v10.14.0
🌐 Added in: v10.14.0
覆盖本地模块的 libc 以进行安装。可接受的值与 package.json 的 libc 字段相同。
🌐 Override libc of native modules to install. Acceptable values are same as libc field of package.json.