title: Webpack - Dynamically importing a class
body: <p>I'm trying to dynamically import a class when a router condition is met.</p>
  
  <p>I have no problems importing a standard (non-class) module, as this works as expected:</p>
  
  <pre><code>Router.on({
      '/:region/map': (params) =&gt; {
        import("Controllers/map.js" /* webpackChunkName: "map" */).then(({map}) =&gt; {
          map.initialise(params.region);
        });
      }
  });
  </code></pre>
  
  <p>But trying to do the same with a class is not working as expected.</p>
  
  <pre><code>Router.on({
      '/:region/map': (params) =&gt; {
        import("Controllers/map.js" /* webpackChunkName: "map" */).then(Map =&gt; {
          Map.initialise(params.region);
        });
      }
  });
  </code></pre>
  
  <p>Which fails 'e.initialise is not a function';</p>
  
  <p>I also try to instantiate the class by using the <code>new</code> keyword:</p>
  
  <pre><code>Router.on({
      '/:region/map': (params) =&gt; {
        import("Controllers/map.js" /* webpackChunkName: "map" */).then(Map =&gt; {
          const MapClass = new Map();
          MapClass.initialise(params.region);
        });
      }
  });
  </code></pre>
  
  <p>But still no joy!</p>
  
  <p>How do I dynamically import a class in this scenario?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>This is my Map module, as a non-class module, which works:</p>
  
  <pre><code>var map = {
      initialise(region) {
          console.log("Map initialised for region: " + region);
      }
  }
  export { map };
  </code></pre>
  
  <p>This is the same module but as a Class:</p>
  
  <pre><code>export default class Map {
      constructor() {
          //
      }
      initialise(region) {
          console.log("Map initialised for region: " + region);
      }
  }
  </code></pre>