适用于Node.js的`.gitignore`

fdj*_*815 14 git github gitignore node.js npm

树结构

这就是我的Node.js项目的组织方式:

/
| - node_modules               [+ INCLUDE]
|   | - my-mod1
|   |   | - node_modules       [- IGNORE]
|   |   |   | - external-mod1 
|   |   |   | - external-mod2 
|   |   | - src
|   |   |   | - node_modules   [+ INCLUDE]
|   |   |   |   | - my-mod2 
|   |   |   |   | - my-mod3
|   | - my-mod4
Run Code Online (Sandbox Code Playgroud)

我的计划

将我的项目发布到GitHub时:

  • 包括my-mods.
  • 不想包括 external-mods.

这意味着:

  • 想要包含顶级/node_modules文件夹.
  • 不希望包括node_modules它们的文件夹直接孩子的模块文件夹.
  • 但我想要包含node_moduels文件夹的子src文件夹.

我做了什么

我添加了以下行/.gitignore:

#################  
## npm
#################

npm-debug.log
node_modules/
!/node_modules/
!src/node_modules/
Run Code Online (Sandbox Code Playgroud)

我的问题

我需要哪些.gitignore规则才能包含正确的node_modules文件夹(如上所述)?

谢谢 - 如果有什么不清楚,请评论.

fun*_*oid 14

由于您的结构非常有条理,您可以使用此模式来完成任务.

/node_modules/*/node-modules/ 
Run Code Online (Sandbox Code Playgroud)

上面的模式将忽略模块文件夹,my-mod1,my-mod4等下的node_modules.

当您推送到github时,上面的行仍然允许包含src目录下的node_modules.


ben*_*ape 8

node_modules/**/node_modules 应该适合你想要做的事情.

提示:GitHub为Node.gitignore等各种语言提供标准.