Search code examples
lazy-loadingwebpack-2

Webpack2 Lazy Loading multiple modules


I need to lazy load multiple files at the same time.

Would be nice to lazy load a modul + its language files

Is there something possible like this?

import(/* webpackChunkName: "chart.js" */ ['chart.js','chart.de.js']).then((Chart, Chart2) => { }

Solution

  • Found the solution here https://survivejs.com/webpack/building/code-splitting/#dynamic-import

    Promise.all([
      import("lunr"),
      import("../search_index.json"),
    ]).then(([lunr, search]) => {
      return {
        index: lunr.Index.load(search.index),
        lines: search.lines,
      };
    });