pnpm add <pkg>
Memasang sebuah paket dan paket apa pun yang bergantung padanya. Secara asali, paket baru apa pun diinstal sebagai dependensi produksi.
SINGKATNYA
Perintah | Berarti |
---|---|
pnpm add sax | Simpan ke dependencies |
pnpm add -D sax | Simpan ke devDependencies |
pnpm add -O sax | Simpan ke optionalDependencies |
pnpm add -g sax | Instal paket secara global |
pnpm add sax@next | Menginstal dari tanda versi next |
pnpm add sax@3.0.0 | Tentukan versi 3.0.0 |
Lokasi paket yang didukung
Pasang dari registri npm
pnpm add nama-paket
akan menginstal versi mutakhir dari nama-paket
dari npm secara asali.
Jika dijalankan di workspace (ruang kerja), perintah pertama-tama akan mencoba memeriksa apakah proyek lain di workspace menggunakan paket yang ditentukan. Jika demikian, rentang versi yang sudah digunakan akan dipasang.
Anda juga dapat memasang paket dengan:
- tanda:
pnpm add express@nightly
- versi:
pnpm add express@1.0.0
- rentang versi:
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 the JSR registry, use the jsr:
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.
Menginstal dari ruang kerja
Perhatikan saat menambahkan dependensi dan bekerja dengan tempat kerja, paket akan diinstal dari sumber yang telah di tentukan, bergantung kepada link-tempat-kerja-paket
telah di set atau tidak, dan penggunaan pada tempat kerja: jangkauan protokol
.
Instal dari file lokal sistem
Ada dua cara untuk menginstal dari sistem file lokal:
- dari berkas tarball (
.tar
,.tar.gz
, atau.tgz
) - dari direktori
Contoh:
pnpm add ./package.tar.gz
pnpm add ./some-directory
Saat Anda menginstal dari direktori, symlink akan dibuat di node_modules
proyek saat ini, jadi ini sama dengan menjalankan pnpm link
.
Instal dari remote tarball
Argumen harus berupa URL yang dapat diambil yang dimulai dengan "http://" atau "http://".
Contoh:
pnpm add http://github.com/indexzero/forever/tarball/v0.5.6
Instal dari repositori 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 the semver:
parameter. Misalnya:
- 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 the path:
parameter. Contohnya:
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
# http
pnpm add http://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 to github:
.
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 the beta
branch and only the subdirectory at /packages/simple-react-app
.
Opsi
--save-prod, -P
Instal paket yang ditentukan sebagai reguler dependencies
.
--save-dev, -D
Instal paket yang ditentukan sebagai devDependencies
.
--save-optional, -O
Instal paket yang ditentukan sebagai optionalDependencies
.
--save-exact, -E
Dependensi yang disimpan akan dikonfigurasikan dengan versi yang tepat daripada menggunakan operator jarak semver standar pnpm.
--save-peer
Menggunakan --save-peer
akan menambahkan satu atau lebih paket ke peerDependencies
dan menginstalnya sebagai dependensi dev.
--config
Added in: v10.8.0
Save the dependency to configDependencies.
--ignore-workspace-root-check
Menambahkan dependency baru ke paket root workspace dipastikan gagal, kecuali jika flag --ignore-workspace-root-check
atau -w
digunakan.
Misalnya, pnpm add debug -w
.
--global, -g
Instal paket secara global.
--workspace
Hanya tambahkan dependency baru jika ditemukan di workspace.
--allow-build
Added in: v10.4.0
A list of package names that are allowed to run postinstall scripts during installation.
Contoh:
pnpm --allow-build=esbuild add my-bundler
This will run esbuild
's postinstall script and also add it to the onlyBuiltDependencies
field of pnpm-workspace.yaml
. So, esbuild
will always be allowed to run its scripts in the future.