title: Webpack dynamic import based on entry name
body: <p>I'm trying to have Webpack to bundle specific files depending on the entry file.</p>
  <p>I have multiple entry files in my project. They all use common helpers functions (separate modules), but some entry files use a slightly modified version.</p>
  <p>Here's what I've done so far:</p>
  <p><strong><code>entry1.js</code></strong></p>
  <pre><code>import helper from './helper';
  
  helper();
  </code></pre>
  <hr />
  <p><strong><code>entry2.js</code></strong></p>
  <pre><code>import helper from './helper';
  
  helper();
  </code></pre>
  <hr />
  <p><strong><code>helper.js</code></strong></p>
  <pre><code>import example from './example';
  
  export default function helper() {
    console.log('common console log for Entry 1 and 2 pages');
  
    example();
  }
  </code></pre>
  <hr />
  <p><strong><code>example.js</code></strong></p>
  <pre><code>const context = window.__CONTEXT__;
  
  export default require(`./example_${context}`).default;
  </code></pre>
  <hr />
  <p><strong><code>example_entry1.js</code></strong></p>
  <pre><code>export default function() {
    console.log('specific console log for Entry 1 page only');
  };
  </code></pre>
  <hr />
  <p><strong><code>example_entry2.js</code></strong></p>
  <pre><code>export default function() {
    console.log('specific console log for Entry 2 page only');
  };
  </code></pre>
  <hr />
  <p><strong><code>entry1.html</code></strong></p>
  <pre><code>&lt;script&gt;
    window.__CONTEXT__ = 'entry1';
  &lt;/script&gt;
  &lt;script src=&quot;entry1.js&quot; /&gt;
  </code></pre>
  <p>Browser's console output:</p>
  <blockquote>
  <p>common console log for Entry 1 and 2 pages</p>
  <p>specific console log for Entry 1 page only</p>
  </blockquote>
  <hr />
  <p><strong><code>entry2.html</code></strong></p>
  <pre><code>&lt;script&gt;
    window.__CONTEXT__ = 'entry2';
  &lt;/script&gt;
  &lt;script src=&quot;entry2.js&quot; /&gt;
  </code></pre>
  <p>Browser's console output:</p>
  <blockquote>
  <p>common console log for Entry 1 and 2 pages</p>
  <p>specific console log for Entry 2 page only</p>
  </blockquote>
  <hr />
  <p>Is there a way to have something like this in <code>example.js</code>?</p>
  <pre><code>export default require(`./example_${__CURRENT_ENTRY_FILENAME__}`).default;
  </code></pre>
  <p>So, Webpack can bundle <code>entry1.js</code> and <code>entry2.js</code> with their specific helper modules!</p>
  <p>And, that way, I'm hoping to get rid of <em>the terrible</em> <code>window.__CONTEXT__</code> in my <code>HTML</code> and <code>JS</code> files.</p>
  <p>Thanks!</p>