pnpm add <pkg>
Installs a package and any packages that it depends on. By default, any new package is installed as a prod dependency.
#
tl;drCommand | Meaning |
---|---|
pnpm add sax | save to dependencies |
pnpm add -D sax | save to devDependencies |
pnpm add -O sax | save to optionalDependencies |
pnpm add [email protected] | Specify tag next |
pnpm add [email protected] | Specify version 3.0.0 |
#
Supported package locationsA package can be installed from different locations:
#
Install from npm registrypnpm add package-name
will install the latest version
of package-name
from the npm registry.
You may also install packages by:
- tag:
pnpm add [email protected]
- version:
pnpm add [email protected]
- version range:
pnpm add [email protected] [email protected]">=0.1.0 <0.2.0"
#
Install from the workspaceNote 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
.
#
Install from local file systemThere are two ways to install from the local file system:
- from a tarball file (
.tar
,.tar.gz
, or.tgz
) - from a directory
Examples:
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
.
#
Install from remote gzipped tarballThe argument must start with "http://" or "https://".
Example:
#
Install from Git repositoryInstalls the package from the hosted Git provider, cloning it with Git.
You may install from Git by:
- latest commit from master:
pnpm add kevva/is-positive
- commit:
pnpm add kevva/is-positive#97edff6f525f192a3f83cea1944765f769ae2678
- branch:
pnpm add kevva/is-positive#master
- version range:
pnpm add kevva/is-positive#semver:^2.0.0
#
Options#
--save-prod, -PThis will install one or more packages in your dependencies
.
#
--save-dev, -DUsing --save-dev
or -D
will install one or more packages in your devDependencies
.
#
--save-optional, -OUsing --save-optional
or -O
will install one or more packages in your optionalDependencies
.
#
--save-exact, -ESaved dependencies will be configured with an exact version rather than using pnpm's default semver range operator.
#
--save-peerAdded in: v3.2.0
Using --save-peer
will add one or more packages to peerDependencies
and install them as dev dependencies.
#
--ignore-workspace-root-check, -WAdded 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
.
#
--globalInstall a package globally.
#
--filter <package_selector>#
--workspaceAdded in: v4.4.0
Only adds the new dependency if it is found in the workspace.