title: How do I import all files in a folder as an module and export all as an object?
body: <p>I'm trying to make every file exported as module in a certain folder, to be imported used as a single object. How should I do this?</p>
  
  <p>I had made a javascript plugin with a long long single file. and I'm now trying to make it to be separated by several files. I'm using Webpack for it.</p>
  
  <p>And, in my plugin code, there was a huge object named "fn" which contains 40~50 functions with 200~300lines each. To split them, I made a folder named "fn" and puts each functions as each files. Each name of file and name of function are identical. so function named "foo" is exported by default in a file named "foo.js" in "fn" folder.</p>
  
  <p>And now I'm trying to import them all and export it as a single object like this.</p>
  
  <p><strong>src/fn/foo_or_whatever.js</strong></p>
  
  <pre><code>export default function aFunctionWhichIUse(){
    // return whatever;
  }
  </code></pre>
  
  <p><strong>src/fn/index.js</strong></p>
  
  <pre><code>import foo from './foo';
  import bar from './bar';
  import fooz from './fooz';
  import baz from './baz';
  import kee from './kee';
  import poo from './poo';
  import tar from './tar';
  import doo from './doo';
  .
  .
  .
  import foo_or_whatever from './foo_or_whatever';
  
  export default {
    foo,
    bar,
    fooz,
    baz,
    kee,
    poo,
    tar,
    doo,
    .
    .
    .
    foo_or_whatever,
  }
  </code></pre>
  
  <p><strong>src/index.js</strong></p>
  
  <pre><code>import fn from './fn'
  </code></pre>
  
  <p>But I don't think it does make sense. Now I have to type same word every four times just to add a function in a "fn" object.</p>
  
  <p>I've found that importing all files from folder is not supported in import/export system. then, What should I use and how should I write code to do that?</p>
  
  <p>Is there some way to do like this? I don't matter whether the way is or not import/export system, as long as if the way works on the webpack.</p>
  
  <p><strong>src/index.js</strong></p>
  
  <pre><code>import * as fn from './fn';
  </code></pre>