Output a UMD module from dynamic sources with webpack : <p>I have a project structure that contains a folder that I want to dynamically import into a UMD module when I build my webpack config and have each file be a submodule in the outputted build.</p>

<p>For example, let's say my sources look like:</p>

<pre><code>/src/snippets/red.js
/src/snippets/green.js
/src/snippets/blue.js
</code></pre>

<p>I want webpack to build these sources into a single module that allows me to access each one as submodules, like so;</p>

<pre><code>const red = require('snippets').red
</code></pre>

<p>I tried iterating over the snippets directory and creating an object with filenames and paths, but I can't figure out what configuration property will instruct webpack to bundle them into a single file and export each. Here's what I have so far:</p>

<pre><code>const glob = require('glob')

module.exports = {
    entry: glob.sync('./src/snippets/*.js').reduce((files, file) =&gt; {
        files[path.basename(file,'.js')] = file

        return files
    }, {}),
    output: {
      path: __dirname + '/lib',
      filename: 'snippets.js',
      libraryTarget: 'umd'
    }
}
</code></pre>

<p>This errors out with: <code>Conflict: Multiple assets emit to the same filename ./lib/snippets.js</code></p>

<p>Any idea on how I can accomplish what I'm looking for?</p>
