Movatterモバイル変換


[0]ホーム

URL:


Перейти к основному содержимому
Версия: 10.x

pnpm add <pkg>

Устанавливает пакет и все его зависимости.По умолчанию любой новый пакет устанавливается как production зависимость.

TL;DR

КомандаОбозначение
pnpm add saxSave todependencies
pnpm add -D saxSave todevDependencies
pnpm add -O saxSave tooptionalDependencies
pnpm add -g saxУстановить глобально
pnpm add sax@nextInstall from thenext tag
pnpm add sax@3.0.0Specify version3.0.0

Поддерживаемые источники пакетов

Установить из npm реестра

pnpm add package-name will install the latest version ofpackage-name fromthenpm registry by default.

Если команда выполняется в рабочем пространстве (воркспейсе), она сначала попытается проверить, используют ли другие проекты в рабочем пространстве (воркспейсе) указанный пакет. Если да, то будет установлена версия из уже используемого диапазона версий.

Вы также можете устанавливать пакеты такими способами:

  • tag:pnpm add express@nightly
  • version:pnpm add express@1.0.0
  • version range:pnpm add express@2 react@">=0.1.0 <0.2.0"

Install from the JSR registry

Added in: v10.9.0

To install packages from theJSR registry, use thejsr: protocol prefix:

pnpm add jsr:@hono/hono
pnpm add jsr:@hono/hono@4
pnpm add jsr:@hono/hono@latest

This works just like installing from npm, but tells pnpm to resolve the package through JSR instead.

Установить из воркспейса

Note that when adding dependencies and working within aworkspace, packageswill be installed from the configured sources, depending on whether or notlink-workspace-packages is set, and use of theworkspace: range protocol.

Установить из локальной файловой системы

Есть два способа установки из локальной файловой системы:

  1. from a tarball file (.tar,.tar.gz, or.tgz)
  2. из папки

Примеры:

pnpm add ./package.tar.gz
pnpm add ./some-directory

When you install from a directory, a symlink will be created in the currentproject'snode_modules, so it is the same as runningpnpm link.

Установить из архива по ссылке

Аргументом должен быть URL-адрес, начинающийся с "http://" или "https://".

Пример:

pnpm add https://github.com/indexzero/forever/tarball/v0.5.6

Установить из Git репозитория

pnpm add <git remote url>

Installs the package from the hosted Git provider, cloning it with Git.

You may install packages from Git by:

  • Latest commit from default branch:
pnpm add kevva/is-positive
  • Git commit hash:
pnpm add kevva/is-positive#97edff6f525f192a3f83cea1944765f769ae2678
  • Git branch:
pnpm add kevva/is-positive#master
  • Git branch relative to refs:
pnpm add zkochan/is-negative#heads/canary
  • Git tag:
pnpm add zkochan/is-negative#2.0.1
  • V-prefixed Git tag:
pnpm add andreineculau/npm-publish-git#v0.0.7

Install from a Git repository using semver

You can specify version (range) to install using thesemver: parameter. For example:

  • Strict semver:
pnpm add zkochan/is-negative#semver:1.0.0
  • V-prefixed strict semver:
pnpm add andreineculau/npm-publish-git#semver:v0.0.7
  • Semver version range:
pnpm add kevva/is-positive#semver:^2.0.0
  • V-prefixed semver version range:
pnpm add andreineculau/npm-publish-git#semver:<=v0.0.7

Install from a subdirectory of a Git repository

You may also install just a subdirectory from a Git-hosted monorepo using thepath: parameter. For instance:

pnpm add RexSkz/test-git-subdir-fetch#path:/packages/simple-react-app

Install from a Git repository via a full URL

If you want to be more explicit or are using alternative Git hosting, you might want to spell out full Git URL:

# git+ssh
pnpm add git+ssh://git@github.com:zkochan/is-negative.git#2.0.1

# https
pnpm add https://github.com/zkochan/is-negative.git#2.0.1

Install from a Git repository using hosting providers shorthand

You can use a protocol shorthand[provider]: for certain Git providers:

pnpm add github:zkochan/is-negative
pnpm add bitbucket:pnpmjs/git-resolver
pnpm add gitlab:pnpm/git-resolver

If[provider]: is omitted, it defaults togithub:.

Install from a Git repository combining different parameters

It is possible to combine multiple parameters by separating them with&. This can be useful for forks of monorepos:

pnpm add RexSkz/test-git-subdir-fetch.git#beta\&path:/packages/simple-react-app

Installs from thebeta branch and only the subdirectory at/packages/simple-react-app.

Опции

--save-prod, -P

Install the specified packages as regulardependencies.

--save-dev, -D

Install the specified packages asdevDependencies.

--save-optional, -O

Install the specified packages asoptionalDependencies.

--save-exact, -E

Сохраненные зависимости будут настроены с использованием точной версии, а не с помощью оператора диапазона semver, который используется по умолчанию.

--save-peer

Using--save-peer will add one or more packages topeerDependencies andinstall them as dev dependencies.

--save-catalog

Added in: v10.12.1

Save the new dependency to the defaultcatalog.

--save-catalog-name <catalog_name>

Added in: v10.12.1

Save the new dependency to the specifiedcatalog.

--config

Added in: v10.8.0

Save the dependency toconfigDependencies.

--ignore-workspace-root-check

Adding a new dependency to the root workspace package fails, unless the--ignore-workspace-root-check or-w flag is used.

For instance,pnpm add debug -w.

--global, -g

Установить пакет глобально.

--workspace

Добавляет новую зависимость, только если она найдена в воркспейсе.

--allow-build

Added in: v10.4.0

A list of package names that are allowed to run postinstall scripts during installation.

Пример:

pnpm --allow-build=esbuild add my-bundler

This will runesbuild's postinstall script and also add it to theonlyBuiltDependencies field ofpnpm-workspace.yaml. So,esbuild will always be allowed to run its scripts in the future.

--filter <package_selector>

Read more about filtering.


[8]ページ先頭

©2009-2025 Movatter.jp