为什么需要在git repo中删除node_modules文件夹?

时间:2018-02-25 17:30:52

标签: node.js git react-native node-modules

为什么有必要忽略git repo中的node_modules?

其他将使用我的代码来自repo的用户,他们不需要我的node_modules文件夹吗?

3 个答案:

答案 0 :(得分:0)

这些模块是应用程序的外部依赖项,您应该相应地在packages.json中添加它们。

您不必包含这些软件包的完整源代码,因为您可以使用一个命令安装它们:npm install,以及其他许多原因(请参阅jfriend00评论)。

通常,在开发应用时,我们会将node_modules添加到.gitignore,以防止依赖项被版本化。

没有必要(你可以随时做你想做的事),但强烈建议你保持你的回购清洁和可维护。

答案 1 :(得分:0)

node_module 太大,您已经有 package.json ,这有助于在{strong> node_module 中按npm install安装所有软件包/ yarn install命令。

保持小巧,干净和可维护,因此在 .gitignore 文件中添加 node_module

答案 2 :(得分:0)

没有必要对整个node_modules进行版本化,因为您使用package.json文件实现了相同的目标,该文件是应用程序所需的依赖项的描述。

当其他用户签入您的版本化代码时,使用package.json文件中提供的描述就可以使用简单的npm install来收集这些依赖项。

比照。 Why is the node_modules folder not committed to Git?