4

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 . ??

programoholic
  • 4,830
  • 5
  • 20
  • 59
  • You could use `yarn` instead, as `yarn` does cache everything locally, similar to an m2. No need to change the `package.json`, and it still builds a `node_modules` directory https://yarnpkg.com/lang/en/docs/migrating-from-npm/ – user184994 Nov 10 '18 at 08:20
  • @user184994 but when i do clean build the cache will be cleared . That's why i want to store node_modules into some other location – programoholic Nov 10 '18 at 08:40
  • You can set the yarn cache to store in whatever location you want – user184994 Nov 10 '18 at 08:46
  • cool... then how to i refer that location to import modules ? – programoholic Nov 10 '18 at 11:45
  • 1
    Like with an m2 in maven, when you do `yarn install`, it will first look in the cache location (the equivalent of an m2), and if it finds it, it will copy from there to your node modules. – user184994 Nov 10 '18 at 12:45

2 Answers2

5

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.

programoholic
  • 4,830
  • 5
  • 20
  • 59
0

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

Suresh Kumar Ariya
  • 9,516
  • 1
  • 18
  • 27