纱线本地包依赖项 [英] Yarn local packages dependencies

查看:56
本文介绍了纱线本地包依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下文件夹结构:

~(用户主文件夹)- api...- 包.json- 库- 库A...包.json- 库B...包.json

libA/package.json 我有以下本地依赖

依赖项":{"libB": "../libB",},

所以 libA 依赖于 libB.

现在我想在 api 项目中添加为本地包 libA.我执行 cd api &&yarn add ../lib/libA 我得到以下错误/Users/a_user/libB不存在.我知道纱线被视为当前导演 ~/api 所以当读取 libA 的依赖项时,它会看到 ../libB 并将其翻译为~/libB 而不是 ~/lib/libB

有没有办法在没有绝对路径的情况下实现它?

解决方案

是的,有,使用 纱线链接.基本上,yarn link 允许您创建指向本地项目的符号链接.

转到文件夹 libB 并运行:

纱线链接

然后转到文件夹libA并运行:

yarn link libB

注意:libB 必须是 libB 文件夹内的 package.json 上的名称

然后你可以像往常一样要求你的 libB 代码:

const libB = require('libB')

I have the following folder structure:

~ (user home folder)
 - api
    ...
    - package.json
 - lib
    - libA
      ...
      package.json
    - libB
      ...
      package.json

In libA/package.json I have the following local dependency

"dependencies": {
    "libB": "../libB",
  },

So libA depends on libB.

Now I want inside api project to add as local package libA. I execute cd api && yarn add ../lib/libA and I get the following error/Users/a_user/libB doesn't exist. I understand that yarn sees as current director ~/api so when is reading the dependency of libA it sees ../libB and translate it as ~/libB and not as ~/lib/libB

Is there anyway to achieve it without absolute paths ?

解决方案

Yes, there is, using yarn link. Basically, yarn link allows you to create symlinks to local projects.

Go to the folder libB and run:

yarn link

Then go to the folder libA and run:

yarn link libB

NOTE: that libB must be the name on the package.json inside the libB folder

Then you can require your libB code as usual:

const libB = require('libB')

这篇关于纱线本地包依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆