title: Webpack ContextReplacementPlugin get packages from node_modules
body: <p>We are trying to make a webpack bundle, which will include all of our dependencies inside a single bundle.</p>
  <p>There is a specific package, which has dynamic requires from node_modules, and webpack can't resolve the packages correctly at compile time.</p>
  <p>The code that generates the error is:</p>
  <pre class="lang-js prettyprint-override"><code>// config.middlewares is a list of packages inside node_modules
  Object.keys(config.middlewares).forEach(function (moduleName) {
    var pkg = require(moduleName)
    var alias = config.middlewares[moduleName]
    helmet[alias] = pkg
  })
  </code></pre>
  <p>Webpack compiles it into:</p>
  <pre class="lang-js prettyprint-override"><code>Object.keys(config.middlewares).forEach(function (moduleName) {
    var pkg = !(function webpackMissingModule() { var e = new Error(&quot;Cannot find module \&quot;.\&quot;&quot;); e.code = 'MODULE_NOT_FOUND'; throw e; }())
    var alias = config.middlewares[moduleName]
    helmet[alias] = pkg
  })
  </code></pre>
  <p>So we tried using Webpack's ContextReplacementPlugin, but whatever we tried we couldn't configure it to change the context to fetch a file from node_modules.</p>
  <p>Somethings we tried (we first tried to just get one specific package, called hsts):</p>
  <pre class="lang-js prettyprint-override"><code>new ContextReplacementPlugin(/helmet.*/, /\.\.\/hsts/)
  new ContextReplacementPlugin(/helmet.*/, /\.\/\.\.\/hsts/)
  new ContextReplacementPlugin(/helmet.*/, /\.\/\.\.\/hsts\/index\.js/)
  ```
  </code></pre>