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)