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:
- run, for example,
npm install -D <module>
incomponent-one
folder - have
package.json
in that folder updated with the<module>
- have
<module>
installed in theproject
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?