2

I have the following folder structure:

project
├───components
│   ├───component-one
│   │       package.json
│   │
│   └───component-two
│       │   package.json
│       │
│       └───node_modules
├───node_modules
└───package.json

Project root project folder contains package.json and is intended to have various infrastructural modules installed (Gulp, for example, as the build is centralized).

Each component under components folder is eventually, after build and whatnot, is deployed somewhere to be consumed by an application - using the usual npm install from folder or tarball. For that reason, each component must maintain its own dependencies in its own package.json.

Going the trivial route, installing node_modules into each of the component folders would lead to a crazy amount of duplication, as there may be 100s of components, each installing mostly the same dependencies.

Ideally I would like to:

  1. run, for example, npm install -D <module> in component-one folder
  2. have package.json in that folder updated with the <module>
  3. have <module> installed in the project folder

This can be achieved, to some extent, running (on Windows, in this case) mklink /D node_modules ..\..\node_modules from component-one to create a symlink.

However, symlinks are fragile and finicky, so I'd like to avoid that solution.

Is there an npm solution, via npm link or something that I am missing?

ZenMaster
  • 12,363
  • 5
  • 36
  • 59
  • 1
    I'm actually looking to do the same thing you tried to achieve here. Have you found a solution since you post this or you just go another road? thx! – Marc-Andre R. Sep 28 '16 at 02:14
  • 1
    @Marc-AndreR. I haven't, unfortunately. That being said, we are looking at Docker, for dev. env setup (which is what this was all about - reduce setup time/issues, with commonly used stuff and it versions). – ZenMaster Sep 28 '16 at 07:59
  • We are also using vagrant/docker to ease the initial setup time/issue but that doesn't reduce the size of the project on the disk. No that we care that much about the space being use, it is more a question of avoiding duplication and keeping things consistent across dependencies.. Thanks anyway for your answer, if I found something on my quest, I'll keep you posted! :) – Marc-Andre R. Sep 28 '16 at 12:14
  • forgot to drop the link to my own question, here you go, in case I got answers that can serve you too : http://stackoverflow.com/questions/39737024/monolytics-repo-and-multiple-node-modules-folder/ – Marc-Andre R. Sep 28 '16 at 12:38

0 Answers0