In Webpack 1, we import code using require.ensure , which can accept an array of modules. These modules are combined into one package and are selected with one HTTP request:
require.ensure(['module1', 'module2'], (require) => { const module1 = require('module1'); const module2 = require('module2'); // use these modules here... }); // ==> both modules are served as a single bundle, eg '5.js'
With Webpack 2, we can now use System.import for a cleaner syntax ... but it looks like System.import only accepts one module for import. Fine - I can use Promise.all - but then I end up with two bundles:
Promise.all([ System.import('module1'), System.import('module2') ]).then( (module1, module2) => { // use these modules here... }); // ==> each module served as its own bundle, eg '5.js', '6.js'
Is there a way to use System.import , but still merge the requested modules into one package?
(Yes, in some cases I can add a new module file, which, in turn, imports and consumes both dependencies, and often the best approach, but for some of my use cases it just adds an additional template)
source share