在git中处理node_modules的正确方法是什么? [英] What is the proper way to deal with node_modules in git?
问题描述
我是git和node的初学者.所以我在git中创建了一个新的存储库,并安装了react和babel,而git告诉我该存储库太大.从字面上看,我所做的就是运行这样的内容:
I am a beginner with git and node. So I created a new repository in git, and installed react and babel, and git is telling me that the repository is too large. Literally all I did was run something like this:
created index.html
created app.js
> npm init (initialized package.json)
> npm install --save react react-dom
> npm install --save-dev babel_preset_react
> npm install --save-dev babel_preset_es2015
added babel config to package.json
也许我遗漏了一些东西,但是我什至还没有构建任何东西,而且我已经开始抱怨我的仓库过大. Git桌面甚至抛出OutOfMemory异常!所以我想知道,也许我不应该签入node_modules文件夹.然后我读到这个:
Maybe I'm missing something, but I haven't even built anything yet, and I'm already getting complaints that my repo is too large. Git desktop is even throwing OutOfMemory exceptions! So I wondered, maybe I'm not supposed to check in the node_modules folder. Then I read this:
https://web.archive.org/posts/nodemodules-in -git.html
但是我现在更加困惑.文章说您应该在node_modules中签入所部署的项目.但这并不意味着它仍将是一个大型存储库"吗?
But I am even more confused now. The article says you should check in node_modules for projects that you deploy. But doesn't that mean it's still going to be a "large repository?"
在底部,文章说不要将node_modules添加到gitignore.我认为gitignore只会忽略该文件夹中的文件,而不会提交给git.那么这是在告诉我们不要忽略node_modules吗?就像在签入node_modules吗?
At the bottom, the article says not to add node_modules to gitignore. I think gitignore just ignores the files in that folder from being committed to git. So is this telling us to not ignore node_modules? As in, check-in node_modules?
$ npm在部署时会重建什么?
And what is that $ npm rebuild on deploy?
从npm和git开始,有人可以用更简单的方式解释我应该做什么?
As a beginning to npm and git, can someone explain what I should do in simpler terms?
推荐答案
您无需将node_modules推送到您的仓库中.将node_modules添加到gitignore中,然后在服务器上部署代码时,必须使用以下命令在该节点上安装node_modules:
you don`t need to push node_modules into your repo . Add node_modules to gitignore and when you deploy your code on the server you have to install node_modules over there using command :
npm install
当您在本地安装node_modules时更新package.json,并将其推送到repo.在服务器上运行npm install时,将安装package.json
As your package.json is updated when you locally install node_modules and it is pushed to repo . When you run npm install on the server , all your packages will be installed which are mentioned in package.json
这篇关于在git中处理node_modules的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!