That's how my Node.js project is organized:
/
| - node_modules [+ INCLUDE]
| | - my-mod1
| | | - node_modules [- IGNORE]
| | | | - external-mod1
| | | | - external-mod2
| | | - src
| | | | - node_modules [+ INCLUDE]
| | | | | - my-mod2
| | | | | - my-mod3
| | - my-mod4
When publishing my project to GitHub:
my-mods.external-mods.That means:
/node_modules folder.node_modules folders which are direct childs of a module folder.node_moduels folders which are childs of a src folder.I added the following lines to /.gitignore:
#################
## npm
#################
npm-debug.log
node_modules/
!/node_modules/
!src/node_modules/
Which .gitignore rules do I need to include the right node_modules folders (as described above)?
Thanks - if anything's unclear, please comment.
Since your structure is quite organized you could use this pattern to accomplish the task.
/node_modules/*/node-modules/
The above pattern will ignore node_modules under module folders, my-mod1,my-mod4 and others.
The above line will still allow the node_modules under src directory to be included when you push to github.
Thanks for your answers.
I rethought the condition and decided to declared the condition the other way - it works perfectly:
node_modules/*/node_modules
I hope this is able to help anybody in the future.
node_modules/**/node_modules should work for what you are trying to do.
Tip: GitHub provides standard .gitignore's for various languages like Node.
node_modules/*
!node_modules/**/node_modules
maybe?