pnpm link
Aliases: ln
現在のローカルパッケージをシステム全体、あるいは、別の場所からアクセス可能にします。
pnpm link <dir>
pnpm link --global
pnpm link --global <pkg>
Options
--dir <dir>, -C
- Default: Current working directory
- Type: Path string
Changes the link location to <dir>.
pnpm link <dir>
Links package from <dir> folder to node_modules of package from where you're executing this command or specified via --dir option.
For example, if you are inside
~/projects/fooand you executepnpm link --dir ../bar, thenfoowill be linked tobar/node_modules/foo.
pnpm link --global
Links package from location where this command was executed or specified via --dir option to global node_modules, so it can be referred from another package with pnpm link --global <pkg>. Also if the package has a bin field, then the package's binaries become available system-wide.
pnpm link --global <pkg>
Links the specified package (<pkg>) from global node_modules to the node_modules of package from where this command was executed or specified via --dir option.
Difference between pnpm link <dir> and pnpm link --dir <dir>
pnpm link <dir> links the package from <dir> to the node_modules of the package where the command was executed. pnpm link --dir <dir> links the package from the current working directory to <dir>.
# The current directory is foo
pnpm link ../bar
- foo
- node_modules
- bar -> ../../bar
- bar
# The current directory is bar
pnpm link --dir ../foo
- foo
- node_modules
- bar -> ../../bar
- 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, while the package.json won't be modified.
cd ~/projects/foo
pnpm install # foo の依存関係をインストールする
pnpm link --global # foo をグローバルにリンクする
cd ~/projects/my-project
pnpm link --global foo # foo を my-project にリンクする
You can also link a package from a directory to another directory, without using the global node_modules folder:
cd ~/projects/foo
pnpm install # foo の依存関係をインストールする
cd ~/projects/my-project
pnpm link ~/projects/foo # foo を my-project にリンクする