title: Using local modules with Webpack 4 is bundling the same dependency multiple times
body: <p>I am attempting to find a good way to use local modules in npm, or a way of structuring a large application so it can be bundled off into modules which may or may not be in a separate repository.</p>
  
  <p>Each local module has it's own package.json and dependencies which are installed.</p>
  
  <p>My requirements are that the modules are written in ES6 and only compiled as part of the main project being built (so I don't have lots of dependencies being indiependently built constantly).</p>
  
  <p>Project structure</p>
  
  <pre><code>/root
    /main-module 
      ... main js files &lt;- entry point
      webpack.config.js
      package.json
    /module-1
      ... module 1 js files
      package.json
    /module-2
      ... module 2 js files
      package.json
    /module-3
      ... module 3 js files
      package.json
  </code></pre>
  
  <p>I'm currently investigating using local modules via specifying a local file in my package.json like so:</p>
  
  <pre><code>...
  "dependencies": {
    "lodash": "^4.17.10",
    "module-1": "../module-1",
    "module-2": "../module-2",
    "module-3": "../module-3",
    "normalize.css": "^8.0.0"
  }
  ...
  </code></pre>
  
  <p>You can see the whole project here: <a href="https://github.com/SamStonehouse/webpack-local-modules-test" rel="nofollow noreferrer">https://github.com/SamStonehouse/webpack-local-modules-test</a></p>
  
  <p>I'm using webpack with the babel-loader which doesn't need any extra setup in order to use this form and even watches the module file for changes and rebuilds when they're complete which is amazing.</p>
  
  <p>Issue: once this has built lodash is included in the built bundle 4 times over, one for each module which requires it, even though they all require the same version and all the sources are compiled at the same time.</p>
  
  <ul>
  <li>I've tried using the splitChunkPlugin but to no avail</li>
  <li>I've tried setting lodash as a devDependency in the local modules (this was something I didn't want to do but it didn't work anyway)</li>
  </ul>
  
  <p>Does anyone have a solution for this?</p>
  
  <p>Or an alternative way of bundling local modules in a similar fashion</p>