Перейти до основного змісту
Версія: 11.x

pnpm link

Aliases: ln

Links a local package to the current project's node_modules.

pnpm link <dir>

Параметри

Звʼязує пакунок з теки <dir> node_modules пакунка, з якого ви виконуєте цю команду. <dir> must be a relative or absolute path.

For example, if you are inside ~/projects/foo and you execute pnpm link ../bar, then a link to bar will be created in foo/node_modules/bar.

Приклади використання

Заміна встановленого пакунка на локальну версію

Let's say you have a project that uses foo package. You want to make changes to foo and test them in your project. In this scenario, you can use pnpm link to link the local version of foo to your project:

cd ~/projects/foo
pnpm install # встановити залежності foo
cd ~/projects/my-project
pnpm link ~/projects/foo # звʼязати foo з my-project

Додавання двійкового файлу глобально

To make a local package's binaries available system-wide, use pnpm add -g . instead:

cd ~/projects/foo
pnpm install # install dependencies of foo
pnpm add -g . # register foo's bins globally

Remember that the binary will be available only if the package has a bin field in its package.json.

When you use pnpm link, the linked package is symlinked from the source code. Ви можете змінювати вихідний код повʼязаного пакунка, і ці зміни будуть відображатися у вашому проєкті. За допомогою цього методу pnpm не встановить залежності повʼязаного пакунка, вам доведеться встановити їх вручну у вихідному коді. This may be useful when you have to use a specific package manager for the linked package, for example, if you want to use npm for the linked package, but pnpm for your project.

When you use the file: protocol in dependencies, the linked package is hard-linked to your project node_modules, you can modify the source code of the linked package, and the changes will be reflected in your project. With this method pnpm will also install the dependencies of the linked package, overriding the node_modules of the linked package.

інформація

When dealing with peer dependencies it is recommended to use the file: protocol. Це краще розвʼязує прямі залежності з залежностями проєкту, гарантуючи, що повʼязана залежність правильно використовує версії залежностей, вказані у вашому основному проєкті, що призводить до більш узгодженої та очікуваної поведінки.

Функціяpnpm linkfile: Protocol
Символічне посилання/Жорстке посиланняСимволічне посиланняЖорстке посилання
Відображає зміни вихідного кодуТакТак
Встановлює залежності повʼязаного пакункаНі (потрібне встановлення вручну)Yes (overrides node_modules of the linked package)
Використання іншого менеджера пакунків для залежностейPossible (e.g., use npm for linked pkg)Ні, використовуватиметься pnpm