0

Webpack seems to be including some extra code instead of chunking, maybe I am not understanding import correctly?

import {detector as d1} from './summernote';

class Detector {
    loadModules() {
        // assume d1() returns false
        d1() ? System.import('./summernote').then(this.instantiateModule) : undefined;
    }
    instantiateModule(importedModule) {
        new importedModule.default();
    }
}

export default Detector;

It seems to be bundling Summernote (the default export from './summernote') when I don't want it to.

If I remove the initial import and put true in place of d1() it correctly chunks Summernote.

Is there any way to make it so that it includes the member {detector} in the bundle, but puts the Summernote default export in a separate chunk?

Ray
  • 2,713
  • 3
  • 29
  • 61
  • Not really. As soon as you import a library - the entire library is added to the bundle. Chunking does not mean splitting SAME library into chunks - it means splitting your application code and dependencies into chunks. What you are trying to achieve is a little bit different from what webpack does. – Pavel Denisjuk Jun 02 '17 at 07:25
  • It's not useful to use `import` and `import()` together. Just use one. If you want to code split, use the latter. If you want to bundle everything all together, use the first one. – Ematipico Jun 02 '17 at 08:50

0 Answers0