10

If I install any grunt plugin, it is added to a folder named "node_modules" in the root of my project dir per default.

My question: is it possible to move this whole folder (and therefore all plugins) to another location (but still within my project folder), let's say to "build/node_modules" ?

Of course, I still want to be able to run grunt from anywhere in my project hierarchy after this change.

frontend_dev
  • 1,693
  • 14
  • 28

2 Answers2

6

Nope, that's a feature of the Node.JS core files. In the case you don't know, Node.JS is the platform which Grunt was built.

All require() calls which don't point to an absolute file or start with ./ will try to find modules inside node_modules folders.

gustavohenke
  • 40,997
  • 14
  • 121
  • 129
  • 4
    See also [this issue](https://github.com/isaacs/npm/issues/775) where the npm maintainer explains why he won't make this possible – explunit May 24 '13 at 15:14
  • Thank you! OK, so while I only want "node_modules" to be in a subdirectory of my project (_not_ installed globally!), it seems that this is also not possible. – frontend_dev May 24 '13 at 15:24
  • It's certainly possible to install node_modules as a subdirectory of your project, in fact this is exactly how you should be doing it. If you're not familiar with installing node dependencies, you should read up on it here https://npmjs.org/doc/install.html. – imjared May 24 '13 at 15:28
  • 6
    Well, what I actually want is "node_modules" to be not a dir directly under my project folder, but rather in a _subdir_ of my project folder, like this: "build/node_modules" instead of just: "node_modules" – frontend_dev May 24 '13 at 16:04
  • I think I'd rather have a node_module path so I'm not pulling down these directory trees of modules times infinity per project. Just a set location more projects could draw from. Doesn't seem like that node_module structure is going to scale well either based on what I'm seeing with replications in modules used by other modules. – Mark Mar 25 '15 at 18:42
1

You can use symbolic link ln -s /original_node_modules_path/node_modules ./node_modules

Toni Chaz
  • 651
  • 11
  • 22