private compileMultiEntry()

in packages/build-tools/breezr-plugin-os/src/MultiEntryManifest.ts [34:75]


  private compileMultiEntry(compiler: Compiler, _compilation: compilation.Compilation) {
    const webpackConfig = compiler.options;
    const manifestStr = _compilation.assets[this.options.entryName];
    const manifest = JSON.parse(manifestStr.source());

    if (isObject(webpackConfig.entry) && webpackConfig.output?.path) {
      // process the json
      const entries = Object.keys(webpackConfig.entry);
      if (entries.length == 1) {
        return;
      }

      entries.forEach((entryId) => {
        if (!manifest.entrypoints[entryId]) {
          return;
        }

        // @ts-ignore
        Object.values(manifest.entrypoints[entryId]).forEach((entryPaths: string[]) => {
          entryPaths.forEach((entryPath) => {
            if (!_compilation.assets[entryPath]) {
              return;
            }
            _compilation.assets[entryPath] = new RawSource(
              _compilation.assets[entryPath].source().replace(
                `window.__CONSOLE_OS_GLOBAL_HOOK__("${this.options.entryName.replace('.manifest.json', '')}`,
                `window.__CONSOLE_OS_GLOBAL_HOOK__("${entryId}`,
              ),
            );
          });
        });

        _compilation.assets[`${entryId}.manifest.json`] = new RawSource(JSON.stringify({
          ...manifest,
          name: entryId,
          entrypoints: {
            [entryId]: manifest.entrypoints[entryId],
          },
        }, null, 2));
      });
    }
  }