简体   繁体   English

如何管理多个节点项目?

[英]How to manage multiple node projects?

We are using 3 different node projects: Project 1 , Project 2 and Project 3 using react and webpack . 我们正在使用3个不同的节点项目:使用reactwebpack的 Project 1Project 2Project 3 All 3 projects are hosted in 3 different repositories. 所有3个项目都托管在3个不同的存储库中。

Project 1 and Project 2 are independent but Project 3 needs zip file of both Project 1 and Project 2 and are put in Project 3 as devDependencies(node_modules). 项目1项目2是独立的,但项目3需要项目1项目2的 zip文件,并作为devDependencies(node_modules)放在项目3中。

Now the problem comes when we need to make changes in Project 1 or Project 2 so that the new zip file can be used in Project 3 . 现在,当我们需要在Project 1Project 2中进行更改以便新的zip文件可以在Project 3中使用时,问题就来了。

For debugging, we need to change the code in Project 1 or Project 2 and then build a zip using npm pack and then update that zip in Project 3 and stop the build of Project 3 and then uninstall and install that zip again and then run the Project 3 again. 为了进行调试,我们需要更改Project 1Project 2中的代码,然后使用npm pack构建一个zip,然后在Project 3中更新该zip,停止构建Project 3 ,然后再次卸载并安装该zip,然后运行再次进行项目3

The other, a little bit faster, a solution is to build Project 1 or Project 2 using npm pack and then copy the lib file generated and then copy that in /node_modules/Project 1(or2)/lib folder in Project 3 running instance. 另一个稍微快一点的解决方案是使用npm pack构建Project 1Project 2 ,然后复制生成的lib文件,然后将其复制到运行实例Project 3的 /node_modules/Project 1(or2)/lib文件夹中。

Is there a better or faster or more convenient way to do manage all these projects? 是否有更好,更快或更方便的方法来管理所有这些项目?

Please don't suggest lerna . 请不要建议lerna Lerna is a great tool but it needs change in architecture which is not feasible. Lerna是一个很棒的工具,但是它需要改变体系结构,这是不可行的。

Can't you publish project1 and project2 to npm? 不能将project1和project2发布到npm吗?

npm publish project1
npm publish project2

Makes these projects devDependencies in project3. 使这些项目成为project3中的devDependencies。

Then just an npm install in project3 will get the lastest project1 and project2. 然后,只需在project3中进行npm install即可获取最新的project1和project2。

If privacy is a concern, can't you get a private npm repo? 如果您担心隐私问题,您是否无法获得私人npm回购? Yeah it costs. 是的,它要花钱。

Alternatively, you could host your own npm repo on your own server? 或者,您可以在自己的服务器上托管自己的npm存储库?

I would put them all in one repo. 我会将它们全部放入一个回购中。 Then you are guaranteed to know where all the projects are relative to each other. 这样就可以确保您知道所有项目在哪里都是相对的。 Each project is just a sub-folder, and has it's own package.json as it does now. 每个项目都只是一个子文件夹,并且像现在一样拥有自己的package.json

You just need some scripts that will do the zipping and copying to the right place in each project. 您只需要一些脚本即可将其压缩并复制到每个项目中的正确位置。

I would make those scripts run from the top level of the project (which has it's own package.json , in the scripts folder. Some adjustments of .gitignore to stop zip files getting checked in and you should be good. 我将使这些脚本从项目的最高级别运行(在scripts文件夹中具有其自己的package.json 。对.gitignore进行一些调整以停止检入zip文件,您应该会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM