Save node_modules external source tree in development (and not in production)

I prefer to store all generated files and dependencies outside my source tree while working on it.

npm and grunt make this hard: npm will never allow the local node_modules to be moved, so I have to use --global and --prefix . But grunt does not seem to support such a scheme.

How can I achieve my goal given the above limitations?

So, if I have a project:

 foo/ .git/ src/ gruntfile.js package.json 

I do not need additional files in my tree, in particular, node_modules . (Also bower_components and build , etc., but it's about npm.) This directory should remain intact while I work on it and run it. It's all.

Apparently, npm link should do this, but when I tried, it still installed all the dependencies in ./node_modules . Any other appeal that I cannot understand; the documents are not clear.

A related suggestion was to use another directory with a symbolic link for my gruntfile or package.json file, but grunt only allowed a symbolic link and continued to work in my source directory!

So far, the closest I have come to a link to, for example, ~/.cache/foo/node_modules from my project. Despite the fact that it ensures the preservation of prints from my tree, I still have this link cluttering up my workspace.

I want to know if there is a better way. Will some combination of npm install , npm link , ln , ~/.cache , NODE_PATH and PWD allow me to start my project from my source tree and keep it clean from all unhistorical artifacts?

+5
source share
1 answer

Swimming against standards is a very bad idea.

What you can (and should) do is add node_modules/ to your .gitignore (or any other ignore file that you have for your original control system), so you are not using these files.

In addition, you can use a directory such as src/ to organize your code and "hide" it from the required configuration files ( package.json , Gruntfile.coffee , etc.).

+4
source

Source: https://habr.com/ru/post/1211803/


All Articles