Grunt - node_modules folder outside the project

Asked

Viewed 2,482 times

0

Guys, I’m starting in Gruntjs, my folder node_modules has 50MB, that for each project, it gets bad.

I wonder if you have how to leave a standard node_modules folder in one place to use in all projects without having to stay inside the project’s Rais.

Thank you

Example:

my front-end project today:

   nome-do-projeto
   ---node_modules(50mb)
   ---assets
      ---sass
       ---js
   ---build
       ---css
       ---js

I would like the node_modules folder, I was out of the project root.

  • Are you talking about the project on github, server, or where?

  • front-end project, I will try to explain better

  • But the reason to take it from the root is to decrease the weight in the repository? Because if it is, just ignore this directory in the version control system.

  • today I already use the function of ignoring node_modules, in SVN, however I wanted something different(better), I looked looking for some things about installing plugins/dependency as global

  • I really see no problem the folder within the project, you can explain to me what it hinders ?

  • This may sound like a rhetorical question, but you’re using the package.json to control their dependencies?

  • We read work in an agency like front end, and handling a folder with 50MB within each project is bad if I can have another solution. Yes Gabriel use package.json within the project to control dependencies.

Show 2 more comments

2 answers

1


Dude, if you frequently use certain modules like Express, Grunt or Gulp, you can install them as global modules:

npm install -g nome_modulo

Inside your project when you load a dependency Node will search your module inside your project (node_modules), if it does not find it will search in the global node_modules folder.

Node does not usually versioning dependencies. A good practice is to create a file called package.json and define its dependencies there, when someone downloads your project you will only need to run the command:

npm install

So Node downloads and installs the dependencies of your project.

References (in English): package json. node_modules

  • If I’m not mistaken, npm install modulo --save installs the module and adds it to the dependencies of the package.json.

0

A tip that might work, but I didn’t test:

$ cd <global-modules-path>/node-google-timezone # vai para o diretório global do package
$ npm link                                      # cria um link global
$ cd ~/projects/my-node-project                 # vai para o diretório do seu projeto
$ npm link                                      # link-install do package

Reference: NPM link

Browser other questions tagged

You are not signed in. Login or sign up in order to post.