@Angular in the global and non-local repository for all projects


I installed angular / cli like this:

npm install -g @ angular / cli

I created a project like this:

ng new project-name

So far so good, but is it possible that when you create a project with the ng new eating it does not copy the @Angula folder to local and yes it uses the global repository?

Question reason:

A clean, angle-only project has approximately 28,000 files with an approximate total size of 200 MB, so backing up takes a lot of time, which consumes less HD space. I would like to unify the packages that are possible in the global repository and whenever I create my projects they will access the libraries there because all the projects will have the same versions of the libraries and its me updating one all the projects will be updated.

===================================================== ============================

I ran the following lines in the CMD simulating a project from scratch.

I created a Projects folder and inside it I made the commands:

mkdir node_modules
echo {} >> package.json
npm i @angular/cli --save
ng new projeto1 --skip-install

In the end I presented the following message when I used ng new project1

"You can not use the new command inside an Angular CLI project."

asked by anonymous 02.05.2018 / 16:22

1 answer


Yes, you can create a node_modules directory between projects.

From the Node.js documentation


If the module identifier passed to require() is not a core module, and   does not begin with '/' , '../' , or './' , then Node.js starts at the   parent directory of the current module, and adds /node_modules , and   attempts to load the module from that location. Node will not append    node_modules to a path already ending in node_modules .


If it is not found there, then it moves to the parent directory, and   so on, until the root of the file system is reached.


For example, if the file at '/home/ry/projects/foo.js' called    require('bar.js') , then Node.js would look in the following locations,   in this order:

  • /home/ry/projects/node_modules/bar.js
  • /home/ry/node_modules/bar.js
  • /home/node_modules/bar.js
  • /node_modules/bar.js

So, basically, what you should do is create a directory called node_modules at the root of your project directory, saving in that directory the common modules between your projects:

│   package.json    
│   │
│   └───@angular
│       │   ...
│   │   tsconfig.json
│   │   ...
│   │
│   │   tsconfig.json
│   │   ...

Notice how there is only one package.json file that manages the shared directory node_modules .

Incidentally, using the

npm install <nome-do-pacote> --save

will ensure automatic updating of the dependencies section of this file.

02.05.2018 / 18:08