Skip to main content

链接协议

link: 协议允许你将项目连接到外部目录。

¥The link: protocol lets you connect your project to an external directory.

yarn add imgs@link:./static/imgs

¥Links vs portals

由于 link: 引用的目标可能在安装后脚本运行之前不存在,并且由于 Yarn 保证无论执行顺序如何都具有可预测的行为,因此我们需要消除包(包含 package.json 文件,并且可能列出它们自己的依赖)与任意文件夹(可能不包含)之间的歧义。

¥Since the target referenced by link: may not exist until postinstall scripts have run, and since Yarn guarantees a predictable behavior regardless of the execution order, we need to disambiguate packages (which contain package.json files, and may list dependencies of their own) from arbitrary folders (which may not).

实际上,这意味着 link: 依赖只能指向任意文件夹 - 换句话说,无论它引用什么,都不能有 package.json 文件,因此不能有依赖。如果你需要符号链接到包,请改用 portals

¥In practice, this means that link: dependencies can only point to arbitrary folders - in other words, whatever it references cannot have a package.json file, and thus can't have dependencies. If you need to symlink to a package, use portals instead.