NPM: Can we store node_modules into a common folder and use it in Angular projects?

Viewed 1790

Can we store node_modules into a common folder instead of local repository folder(node_modules) and then use this common folder into angular project? i will explain my requirement via a flowchart : enter image description here

I know its recommended that we are highly encouraged to place the dependencies locally in node_modules folders so that they will be loaded faster, and more reliably. But still i am trying to create a common local repo(like m2 in maven) which contains modules locally.

  • First of all, is it a good idea ? (in my point of view if i able to do this, the CD process will be reduced to 2-3 minutes from 20-25 minutes) [ We perform clean build hence agent clears local changes from the repository so npm install is required]

  • All the dependencies are of fixed version(no upgradation automatically)

  • How do I configure npm to store the packages into common folder instead of local node_modules

  • How do I import packages present in common repository into my angular codebase

Can anyone help me on this . ??

2 Answers

I was finally able to achieve this by implementing Yarn.

We have to set cache path as . :

yarn config set cache-folder /usr/local/Caches/yarn

After implementing this. I was able to successfully achieve the above mentioned requirement.

Option1:

You can move the node_modules folder inside src/lib folder and update package.json to point to local src/lib path. For this to achieve, we need to use yarn.

Option2:

You can move all the node_modules to your custom git repo, modify the checkout path to custom git repo in package.json/config.xml. During npm install , it will load from custom git repo.

how to specify local modules as npm package dependencies

Related