跳至主要內容
版本:6.x

pnpm install

命令別名:i

使用 pnpm install 來為專案安裝所有相依套件。

在 CI 環境中,如果 lockfile 存在但需要更新時,會使安裝失敗。

workspace 中,pnpm install 會安裝所有專案的相依套件。 如要停用此行為,請將 recursive-install 設為 false

TL;DR

命令效果
pnpm i --offline僅從儲存區離線安裝套件
pnpm i --frozen-lockfile不更新 pnpm-lock.yaml
pnpm i --lockfile-only僅更新 pnpm-lock.yaml

選項

--offline

  • 預設值:false
  • 類型:Boolean

此值為 true 時,pnpm 只使用儲存區中可用的套件。 如果在本機無法找到套件,則安裝會失敗。

--prefer-offline

新增於 v1.28.0

  • 預設值:false
  • 類型:Boolean

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.

--ignore-scripts

  • 預設值:false
  • 類型:Boolean

Do not execute any scripts defined in the project package.json and its dependencies.

注意事項

This flag does not prevent the execution of .pnpmfile.cjs

--prod, -P

pnpm will not install any package listed in devDependencies if the NODE_ENV environment variable is set to production. Use this flag to instruct pnpm to ignore NODE_ENV and take its production status from this flag instead.

--dev, -D

Only devDependencies are installed regardless of the NODE_ENV.

--no-optional

optionalDependencies 未安裝。

--lockfile-only

Added in: v1.26.0 (initially named shrinkwrap-only)

  • 預設值:false
  • 類型:Boolean

When used, only updates pnpm-lock.yaml and package.json. Nothing gets written to the node_modules directory.

--fix-lockfile

新增於 v6.15.0

自動修復損壞的 lockfile。

--frozen-lockfile

Added in: v1.37.1 (initially named frozen-shrinkwrap)

  • 預設值:
    • For non-CI: false
    • For CI: true, if a lockfile is present
  • 類型:Boolean

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.

--reporter=<name>

  • 預設值:
    • For TTY stdout: default
    • For non-TTY stdout: append-only
  • Type: default, append-only, ndjson, silent

Allows you to choose the reporter that will log debug info to the terminal about the installation progress.

  • silent - no output is logged to the console, except fatal errors
  • default - the default reporter when the stdout is TTY
  • append-only (Added in v1.29.1) - the output is always appended to the end. No cursor manipulations are performed
  • ndjson - the most verbose reporter. Prints all logs in ndjson format

--use-store-server

新增於 v1.30.0

  • 預設值:false
  • 類型:Boolean

Starts a store server in the background. The store server will keep running after installation is done. To stop the store server, run pnpm server stop

--shamefully-hoist

  • 預設值:false
  • 類型:Boolean

Creates a flat node_modules structure, similar to that of npm or yarn. WARNING: This is highly discouraged.

--filter <package_selector>

閱讀更多關於 filter 的資訊。