NPM是否忽略.gitignore中列出的文件? [英] Does NPM ignore files listed in .gitignore?
问题描述
我有一个由 npm install
命令(使用 preinstall
任务)生成的文件。我不想将它添加到git存储库或NPM项目中。
I have a file that is generated by npm install
command (using preinstall
task). I don't want to add it in the git repository, nor in the NPM project.
假设文件名是 foo.json code>,我将它作为
foo.json
添加到 .gitignore
文件中。
Supposing the file name is foo.json
, I added it in .gitignore
file as foo.json
.
这足以避免上传到NPM注册表吗?
Is this enough to avoid uploading it on NPM registry?
我知道我可以添加 .npmignore code>文件,肯定会忽略该文件,但如果
.gitignore
已经这样做,我不会添加它。
I know I can add .npmignore
file that will surely ignore the file, but I won't add it if .gitignore
already does this.
推荐答案
From 文档:
$ b
From the documentation:
使用
.npmignore
文件来保持东西不在你的包里。如果没有.npmignore
文件,但是是.gitignore 文件,那么npm会忽略由 包含您的.gitignore
文件匹配的内容。如果您希望.gitignore
文件排除的内容,您可以创建一个空的.npmignore
Use a
.npmignore
file to keep stuff out of your package. If there's no.npmignore
file, but there is a.gitignore
file, then npm will ignore the stuff matched by the.gitignore
file. If you want to include something that is excluded by your.gitignore
file, you can create an empty.npmignore
file to override it.
简单来说,npm 更喜欢 .npmignore
文件(如果存在),但会回退到 .gitignore
文件。因此,如果两者都存在,它将使用 .npmignore
文件。
In simpler terms, npm prefers the .npmignore
file if it is there, but will fall back to the .gitignore
file. So if both are present, it will use the .npmignore
file.
在很多情况下,Git和npm可以忽略相同的文件,所以仅仅使用 .gitignore
文件是有意义的。如果有差异(即npm和Git需要忽略不同的文件),那么你需要维护单独的 .gitignore
和 .npmignore
files。
In many cases, both Git and npm can ignore the same files, so it makes sense to just use a .gitignore
file on its own. If there's ever a discrepancy (i.e. npm and Git need to ignore different files), then you need to maintain separate .gitignore
and .npmignore
files.
有关放入 .npmignore
文件内容的更多信息:我应该.npmignore我的测试?
More information on what to put in .npmignore
files: Should I .npmignore my tests?
这篇关于NPM是否忽略.gitignore中列出的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!