如何在多个NPM软件包上合作工作?
我正在从事一个“主要”项目的情况
,为了将代码分开并使部分可重复使用,我创建了2个NPM项目/软件包:“ A”和“ B”。 “ Main”需要“ A”和“ B”,“ B”需要“ A”,
main
+-- A
`-- B
`-- A
而在项目Main中进行开发时,A和B可能需要进行一些改进,但是为了使A和B内部的更改在Main内生效,我需要要为每个小更改npm链接发布新版本
,yalc,workspaces,
通用方法是npm link
npm workspaces 根据环境和设置的不同,表现不同,同时链接往往会因运行其他NPM命令而混乱,WebPack等也有一些问题等。
YALC
尝试通过复制围绕文件来解决此问题 到软件包中
并将文件放置: / link:依赖项
- 。最新的A / B存在是因为在管道中,这些软件包不是符合链接的,或者文件: / link:依赖项指向
- 小组中工作时不存在的文件夹,即使我按下我的机器上的改进也存在他们进入A和B的存储库,我团队中的其他人需要不断地需要更新其团队
- 中其他人的存储库,需要在其机器上像我一样
git存储库
上的机器上相同的文件夹/链接结构,我添加了A和B作为内部的git依赖关系主要:
main/package.json
"devDependencies": {
"A": "git+https://<link of my git repo>/A.git",
"B": "git+https://<link of my git repo>/B.git",
B/package.json
"devDependencies": {
"A": "git+https://<link of my git repo>/A.git"
很棒,因为我可以简单地推动a或b的更改,每个人都可以通过npm Update
接收最新版本的A和
B。 git依赖项,a和b内部的a和b可以解决,但是A内部B无法解决,这意味着在运行WebPack时,“ A”不存在“ B”现在,
现在什么?
必须有比这更好的解决方案。但是使用真实的软件包,即使它是一个像Verdaccio这样的私人存储库,也意味着每个小更改都需要我创建和发布该软件包的新版本,并用软件包版本垃圾邮件。
Situation
I'm working on a project "main" and in order to split the code and make parts of it reusable, I created 2 npm projects/packages: "A" and "B". "main" requires "A" and "B", "B" requires "A"
main
+-- A
`-- B
`-- A
While developing in project main, A and B might require some improvements, But in order to have changes inside A and B take effect inside main I would need to publish a new version of them for every little change
npm link, yalc, workspaces
The common approach is npm link
or npm workspaces
but it has a few downsides, symlinks tend to behave differently depending on the environment and setup, also the symlinks tend to get messed up by running other npm commands, there are also some issues with webpack etc. etc.
yalc
attempts to solve this by copying files around and putting file: / link: dependencies into the package.json
All of these "local" approaches have a few problems:
- If I push the code of "main" to git, I can't run CI/CD pipelines that rely on the newest A/B being present because in the pipeline, those packages are not symlinked or the file: / link: dependencies point to folders that do not exist
- When working in a small team, the improvements only exist on my machine, even if I push them into the repositories of A and B, others in my team would need to constantly need to update their repositories
- others in my team would need the same folder/link structure on their machines like me
git repositories
I added A and B as git dependencies inside main:
main/package.json
"devDependencies": {
"A": "git+https://<link of my git repo>/A.git",
"B": "git+https://<link of my git repo>/B.git",
B/package.json
"devDependencies": {
"A": "git+https://<link of my git repo>/A.git"
Thats great because I can simply push a change in A or B and everybody can receive the newest version of A and B via npm update
The problem here is, that npm sadly but justifiably does not recursively resolve git dependencies, A and B inside main get resolved but A inside B does not get resolved, this means that when running webpack for example, "A" does not exist inside "B"
what now?
There has to be a better solution than this. But using real packages, even if its a private repository like verdaccio, means every little change requires me to create and publish a new version of the package, spamming the repository with package versions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论