本文介绍了应该“node_modules"文件夹包含在 git 存储库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我们是否应该在我们的 repo 中跟踪 node_modules 或在检查代码时进行 npm install?

I'm wondering if we should be tracking node_modules in our repo or doing an npm install when checking out the code?

推荐答案

答案并不像 Alberto Zaccagni 建议的那么简单.如果您开发应用程序(尤其是企业应用程序),在您的 git 存储库中包含 node_modules 是一个可行的选择,您选择哪种替代方案取决于您的项目.

The answer is not as easy as Alberto Zaccagni suggests. If you develop applications (especially enterprise applications), including node_modules in your git repo is a viable choice and which alternative you choose depends on your project.

因为他对 node_modules 的论证非常好,所以我将专注于他们的论证.

Because he argued very well against node_modules I will concentrate on arguments for them.

想象一下,您刚刚完成了企业应用程序,您必须支持它 3-5 年.你绝对不想依赖某个人的 npm 模块,因为它明天就会消失,你也不能再更新你的应用了.

Imagine that you have just finished enterprise app and you will have to support it for 3-5 years. You definitely don't want to depend on someone's npm module which can tomorrow disappear and you can't update your app anymore.

或者您拥有无法从 Internet 访问的私有模块,并且您无法在 Internet 上构建您的应用程序.或者,您可能出于某种原因不想依赖于 npm 服务的最终构建.

Or you have your private modules which are not accessible from the internet and you can't build your app on the internet. Or maybe you don't want to depend on your final build on npm service for some reason.

您可以在这篇 Addy Osmani 文章中找到优点和缺点 (虽然是关于鲍尔的,但情况几乎一样).最后我会引用 Bower 主页和 Addy 的文章:

You can find pros and cons in this Addy Osmani article (although it is about Bower, it is almost the same situation). And I will end with a quote from Bower homepage and Addy's article:

如果您编写的包不是供其他人使用的(例如,您正在构建 Web 应用程序),则应始终将已安装的包检查到源代码管理中."

这篇关于应该“node_modules"文件夹包含在 git 存储库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 11:10