function chunkIndexFromWebpackChunks()

in fusion-cli/build/plugins/client-chunk-metadata-state-hydrator-plugin.js [52:85]


function chunkIndexFromWebpackChunks(chunks) {
  const chunkIdsByFile = new Map();

  for (const c of chunks) {
    const chunkId = c.id;

    const files = [];

    // Iterate through the groups this chunk belongs to, adding the files of the other chunks in that group as well
    for (const g of c.groupsIterable) {
      for (const cc of g.chunks) {
        for (const m of cc.modulesIterable) {
          if (m.resource) {
            files.push(m.resource);
          } else if (m.modules) {
            files.push(...m.modules.map(module => module.resource));
          }
        }
      }
    }

    for (const path of files) {
      if (!chunkIdsByFile.has(path)) {
        chunkIdsByFile.set(path, new Set());
      }
      const chunkIds = chunkIdsByFile.get(path);
      if (chunkIds) {
        chunkIds.add(chunkId);
      }
    }
  }

  return chunkIdsByFile;
}