title: share node_modules directory between multiple projects
body: <p>I am a java developer learning EC6. I use npm to download JavaScript packages and webpack to create the final bundle.js file.</p>
  
  <p>I have a nice project folder which contains java modules with java files and I would like to add EC6 JavaScript files to my web-modules. I use maven to manage the java jar dependency libraries.</p>
  
  <p>This is my folder structure:</p>
  
  <pre><code>my-project
    |-common-module
    |-ejb-module
    |-web-module-1
    |   |-src
    |       |-main
    |           |-java
    |               |-com.a.b
    |                   |-Hello.java
    |           |-webapp
    |               |-index.jsp
    |               |-bundle.js
    |               |-package.json
    |               |-webpack.config.js
    |               |-WEB-INF
    |               |-node_modules &lt;-- I WANT THIS FOLDER TO BE MOVED AWAY FROM HERE 
    |               |-app          &lt;-- react + ec6 javascript files
    |                   |-action
    |                   |-components
    |                   |-...
    |-web-module-2
        |-&lt;same structure then under web-module-1&gt;
  </code></pre>
  
  <p>When I execute <strong>npm install...</strong> command in <em>my-project/web-module-1/src/main/webapp</em> folder then a new directory with name of <em>node_modules</em> is created by npm under webapp directory. This folder contains tons of files.</p>
  
  <p>My problem is that when I work on my 2nd web project and execute the same <strong>npm install...</strong> command then a second <em>node_modules</em> directory is created with the same content under <em>my-project/web-module-2/src/main/webapp</em> directory.</p>
  
  <p>Can I use a common, separated <em>node_modules</em> directory to avoid the duplicated files and save disk space?
  Can I store js dependencies under ex. <em>/home/user/javascript/modules</em> folder?</p>
  
  <p>Comment 1: I do not want to execute npm as a root and use <strong>npm -g install</strong>!</p>
  
  <p>Comment 2: I do not want to create symlinks as well.</p>
  
  <p>Could you please help me?</p>
  
  <hr>
  
  <p><strong>EDIT</strong>
  What i did:</p>
  
  <ul>
  <li>I have created a new folder for the JS packages:
  <em>/home/user/javascript-modules</em>.</li>
  <li>Copied <em>package.json</em> file to <em>/home/user/javascript-modules</em>.</li>
  <li><em>npm install --prefix /home/user/javascript-modules</em></li>
  </ul>
  
  <p>After that the necessary JS modules are copied to my <em>javascript-modules/node-modules</em> directory. Nice!</p>
  
  <p>But when I try to execute webpack then i get a missing module error:</p>
  
  <ul>
  <li>cd my-project/web-module-1/src/main/webapp</li>
  <li>./home/user/javascript-modules/node_modules/.bin/webpack</li>
  </ul>
  
  <p><strong>Result:</strong> </p>
  
  <pre><code>Hash: a6bf1a0d210729a54be9
  Version: webpack 1.14.0
  Time: 39ms
  
  ERROR in Entry module not found: Error: Cannot resolve module 'babel-loader' in /home/user/java/intellijmy-project/web-module-1/src/main/webapp
  </code></pre>
  
  <p>Comment: My webpack.config.js files contains a line with this content: <em>loader: 'babel-loader'</em></p>
  
  <p>Is there any way to specify the "classpath" for webpack? I mean to tell to webpack where are a modules.</p>
  
  <hr>
  
  <p><strong>UPDATE</strong>
  As you can see in the comments I have tried to solve my issue on many different ways without any success. For me it seems that what I wanted to do is not supported by webpack. That so sad :(</p>
  
  <p>That is it. If some has any working, nice and complete solution please share it with us. Thanks.</p>