Saltar al contenido principal
Version: 5.x

pnpm add <pkg>

Instalar el paquete y cualquier paquete que dependa de el. Por defecto, cualquier nuevo paquete se instala como una dependencia de producción.

TL;DR

ComandoSignificado
pnpm add saxSe guarda en dependencies
pnpm add -D saxSe guarda en devDependencies
pnpm add -O saxSe guarda en optionalDependencies
pnpm add sax@nextSe instala desde el tag next
pnpm add sax@3.0.0Especificar versión 3.0.0

Ubicaciones de paquetes soportados

Instalar desde el registro de npm

pnpm add package-name will install the latest version of package-name from the npm registry by default. To install a package from another registry, you can use the tarball link (see the corresponding guide).

You may also install packages by:

  • etiqueta: pnpm add express@nightly
  • versión: pnpm add express@1.0.0
  • rango de versiones: pnpm add express@2 react@">=0.1.0 <0.2.0"

Instalar desde el espacio de trabajo

Note that when adding dependencies and working within a workspace, packages will be installed from the configured sources, depending on whether or not link-workspace-packages is set, and use of the workspace: range protocol.

Instalar desde el sistema de archivos local

There are two ways to install from the local file system:

  1. desde un archivo tarball (.tar, .tar.gzo .tgz)
  2. de un directorio

Examples:

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

When you install from a directory, a symlink will be created in the current project's node_modules, so it is the same as running pnpm link.

Instalar desde tarball remoto

The argument must be a fetchable URL starting with "http://" or "https://".

Example:

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

Instalar desde el registro de npm

pnpm add <git remote url>

Installs the package from the hosted Git provider, cloning it with Git. You can use a protocol for certain Git providers. For example, pnpm add github:user/repo

You may install from Git by:

  • último commit del master: pnpm add kevva/is-positive
  • commit: pnpm add kevva/is-positive#97edff6f525f192a3f83cea1944765f769ae2678
  • branch: pnpm add kevva/is-positive#master
  • rango de versiones: pnpm add kevva/is-positive#semver:^2.0.0

Options

--save-prod, -P

Install the specified packages as regular dependencies.

--save-dev, -D

Install the specified packages as devDependencies.

--save-optional, -O

Install the specified packages as optionalDependencies.

--save-exact, -E

Saved dependencies will be configured with an exact version rather than using pnpm's default semver range operator.

--save-peer

Añadido en: v3.2.0

Using --save-peer will add one or more packages to peerDependencies and install them as dev dependencies.

--ignore-workspace-root-check, -W

Added in: v3.6.0

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

Install a package globally.

--workspace

Añadido en: v4.4.0

Only adds the new dependency if it is found in the workspace.

--filter <package_selector>

Read more about filtering.