Browsers which don't support es modules also don't support es2015 and web components for those browsers we load a systemjs build, including: - es5 code - babel polyfills - web component polyfills (no feature detection needed) - systemjs loader for modules
function writeLegacyModules(pluginConfig, outputConfig, entryModules) {
  const legacyOutputDir = outputConfig.dir;
  const outputDir = legacyOutputDir.replace('/legacy', '');
  const indexHTML = getOutputHTML(outputDir);

  const body = query(indexHTML, predicates.hasTagName('body'));
  const polyfillsDir = `${outputDir}/polyfills`;
  mkdirp.sync(polyfillsDir);

  if (pluginConfig.polyfillBabel) {
    append(
      body,
      createScript({
        src: `./polyfills/babel-polyfills.js`,
        nomodule: '',
      }),
    );
  }

  if (pluginConfig.polyfillWebcomponents) {
    append(
      body,
      createScript({
        src: `./polyfills/webcomponent-polyfills.js`,
        nomodule: '',
      }),
    );
  }

  copyFileSync(require.resolve('systemjs/dist/s.min.js'), `${polyfillsDir}/system-loader.js`);
  append(
    body,
    createScript({
      src: `./polyfills/system-loader.js`,
      nomodule: '',
    }),
  );

  const loadScript = createScript(
    { nomodule: '' },
    entryModules.map(src => `System.import('./${pathJoin('legacy', src)}');`).join(''),
  );
  append(body, loadScript);
  writeOutputHTML(outputDir, indexHTML);
}