yarnlink的用法与作用
当我们开发一个库的时候,不可能每次都去发布到npm或者私服,然后再去应用中安装。所以,无论npm或者 yarn都提供了link命令用以简化开发流程。
以yarn为例,首先进入到库的根目录中,执行yarn link,值得注意的时候,当前目录显然应该有package.json文件,且应包含发布的名称和入口文件。
此时相当于将当前包发布到了全局环境,这个时候,对应的应用就可以通过yarn link @scope/your-lib命令添加该包。其实仅仅是创建了一个软连接,即一个快捷方式。
至此就成功绕过了发包的流程,而且得益于仅仅是一个创建一个软连接,使得每次重新构建库之后,应用可以立即看到效果,从而实现快速的本地开发。
yarn官网原文 地址:https://yarn.bootcss.com/docs/cli/link/
Symlink a package folder during development.
For development, a package can be linked into another project. This is often useful to test out new features or when trying to debug an issue in a package that manifests itself in another project.
There are two commands to facilitate this workflow:
yarn link
(in package you want to link)
This command is run in the package folder you’d like to consume. For example if you are working on react
and would like to use your local version to debug a problem in react-relay
, simply run yarn link
inside of the react
project.
yarn link [package...]
Use yarn link [package]
to link another package that you’d like to test into your current project. To follow the above example, in the react-relay
project, you’d run yarn link react
to use your local version of react
that you previously linked.
Complete example, assuming two project folders react
and react-relay
next to each other:
$ cd react
$ yarn link
yarn link vx.x.x
success Registered "react".
info You can now run `yarn link "react"` in the projects where you want to use this module and it will be used instead.
$ cd ../react-relay
$ yarn link react
yarn link vx.x.x
success Registered "react".
This will create a symlink named react-relay/node_modules/react
that links to your local copy of the react
project.
Links are registered in ~/.config/yarn/link
. If you want to specify a different folder you can run the command with this syntax yarn link --link-folder path/to/dir/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 使用C#创建一个MCP客户端
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现