树形结构
这就是我的 Node.js 项目的组织方式:
/
| - node_modules [+ INCLUDE]
| | - my-mod1
| | | - node_modules [- IGNORE]
| | | | - external-mod1
| | | | - external-mod2
| | | - src
| | | | - node_modules [+ INCLUDE]
| | | | | - my-mod2
| | | | | - my-mod3
| | - my-mod4
我的计划
将我的项目发布到 GitHub 时:
- 我想要包含
my-mod
s。 - 我不想包含
external-mod
s。
这意味着:
- 我想要包含顶级
/node_modules
文件夹。 - 我不想包含
node_modules
文件夹,这些文件夹是模块文件夹的直接子。 - 但我想要包含
node_moduels
文件夹,它们是src
文件夹的子文件夹。
我做了什么
我在 /.gitignore
中添加了以下几行:
#################
## npm
#################
npm-debug.log
node_modules/
!/node_modules/
!src/node_modules/
我的问题
我需要哪些.gitignore
规则来包含正确的node_modules
文件夹(如上所述)?
谢谢 - 如果有任何不清楚的地方,请发表评论。
最佳答案
由于您的结构非常有条理,您可以使用此模式来完成任务。
/node_modules/*/node-modules/
上述模式将忽略模块文件夹下的node_modules,my-mod1,my-mod4等。
当你推送到 github 时,上面的行仍然允许包含 src 目录下的 node_modules。
关于git - 适用于 Node.js 的 `.gitignore`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14962451/