I prefer to keep all generated files and dependencies outside my source tree while I work on it.
npm and grunt make that difficult: npm will never allow moving local node_modules, so I have to use --global
and --prefix
. But grunt does not support such a scheme, apparently.
How can I achieve my objective given the above constraints?
So, if I have a project:
foo/
.git/
src/
gruntfile.js
package.json
I want no extra files in my tree, specifically, node_modules
. (Also bower_components
and build
etc but this is about npm.) This directory should remain untouched while I am working on it and running it. That is all.
Apparently npm link
is supposed to do this, but when I tried it still installed all the dependencies in ./node_modules
. Any other invocation I cannot fathom; the docs are not clear.
A related suggestion was to use another directory with symlink to my gruntfile or package.json, but grunt just resolved the symlink and continued to work in my original directory!
So far the closest I have come is to link to e.g. ~/.cache/foo/node_modules
from my project. Although it achieves keeping the deps out of my tree, I still have this link cluttering my workspace.
I want to know if there is a better way. Will some combination of npm install
, npm link
, ln
, ~/.cache
, NODE_PATH
and PWD
allow me to run my project, from my source tree, and keep it clean of all non-source artefacts?
Swimming against standards is a Very Bad Idea ®.
What you can (and should) do is add node_modules/
to your .gitignore
(or whatever ignore file you have for your given source control system) so you don't version these files.
Also, you can use a directory like src/
to organize your code and "shelter" it from the mandatory configuration files (package.json
, Gruntfile.coffee
, etc).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With