pnpm add <pkg>
安装软件包及其依赖 的任何软件包。 默认情况下,任何新软件包都安装为生产依赖项。
摘要:
Command | Meaning |
---|---|
pnpm add sax | Save to dependencies |
pnpm add -D sax | Save to devDependencies |
pnpm add -O sax | Save to optionalDependencies |
pnpm add -g sax | Install package globally |
pnpm add sax@next | Install from the next tag |
pnpm add sax@3.0.0 | Specify version 3.0.0 |
支持的包地址
从 npm 安装
pnpm add package-name
will install the latest version of package-name
from
the npm registry by default.
如果在 workspace 中执行,该命令将首先去检查这个 worksapce 中的其他项目是否已经使用了这个指定的包。 如果是的话,就使用这个包的版本范围来进行安装。
你还可以通过以下方式安装包:
- 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"
从 workspace 安装
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
.
从本地安装
从本地安装的两种方法:
- from a tarball file (
.tar
,.tar.gz
, or.tgz
) - 本地目录
示例:
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
.
从远端安装 Tar 包
参数必须是一个可访问的 URL,"http://" 或者 "https://" 开头的。
示例:
pnpm add https://github.com/indexzero/forever/tarball/v0.5.6
从 git 安装
pnpm add <git remote url>
通过 git clone, 从 git 作者处安装包.
可以用协议准确的指定 git 作者 For example,
pnpm add github:user/repo
您可以通过以下方式从 Git 安装:
- 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
You may also install just a subdirectory from a Git-hosted monorepo. 例如:
pnpm add myorg/repo#path:packages/foo
It is possible to combine multiple parameters by separating them with &
. For instance, you can extend the above command by specifying which branch to fetch from:
pnpm add myorg/repo#path:packages/foo&next
配置项
--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
保存的依赖会被指定为一个确切的版本, 而不是使用 pnpm 的默认 semver range operator 配置.
--save-peer
Using --save-peer
will add one or more packages to peerDependencies
and
install them as dev dependencies.
--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
仅添加在 workspace 找到的依赖项.