import Link from "/snippets/cli/link.mdx";
在本地目录中使用 bun link 将当前包注册为"可链接"包。
bash
cd /path/to/cool-pkg
cat package.json
bun linktxt
bun link v1.3.3 (7416672e)
Success! Registered "cool-pkg"
To use cool-pkg in a project, run:
bun link cool-pkg
Or add it in dependencies in your package.json file:
"cool-pkg": "link:cool-pkg"现在可以使用 bun link cool-pkg 将此包"链接"到其他项目中。这将在目标项目的 node_modules 目录中创建符号链接,指向本地目录。
bash
cd /path/to/my-app
bun link cool-pkg此外,可以使用 --save 标志将 cool-pkg 添加到应用的 package.json 的 dependencies 字段中,并使用特殊的版本说明符告诉 Bun 从注册的本地目录加载,而不是从 npm 安装:
json
{
"name": "my-app",
"version": "1.0.0",
"dependencies": {
"cool-pkg": "link:cool-pkg"
}
}取消链接
在根目录中使用 bun unlink 取消注册本地包。
bash
cd /path/to/cool-pkg
bun unlinktxt
bun unlink v1.3.3 (7416672e)