合适的`.gitignore`对于Node.js
树结构
这就是我的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
。 - 我不想包含
external-mod
。
这意味着:
- 我想包含顶级
/node_modules
文件夹。 - 我不想包含模块文件夹的子
node_modules
文件夹。 - 但是我想包含一个
src
文件夹的子node_moduels
文件夹。
我做了什么
我/.gitignore
添加到/.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。
node_modules/**/node_modules
应该为你正在尝试做的工作。
提示: GitHub为像Node这样的各种语言提供了标准的.gitignore
。
感谢您的回答。
我重新考虑了这个条件,并决定以另一种方式宣布这个条件 – 它完美地工作:
node_modules/*/node_modules
我希望这能够帮助任何人在未来。
node_modules/* !node_modules/**/node_modules
也许?