async function createPolyfillsLoader(cfg) {
    let polyfillFiles = await createPolyfillsData_1.createPolyfillsData(cfg);
    const coreJs = polyfillFiles.find(pf => pf.name === 'core-js');
    polyfillFiles = polyfillFiles.filter(pf => pf !== coreJs);
    const { loadPolyfillsCode, generatedFiles } = createPolyfillsLoaderCode(cfg, polyfillFiles);
    let code = `
    ${createLoadScriptCode(cfg, polyfillFiles)}
    ${loadPolyfillsCode}
    ${createLoadFilesCode(cfg, polyfillFiles)}
  `;
    if (coreJs) {
        generatedFiles.push({
            type: utils_1.fileTypes.SCRIPT,
            path: coreJs.path,
            content: coreJs.content,
        });
        // if core-js should be polyfilled, load it first and then the rest because most
        // polyfills rely on things like Promise to be already loaded
        code = `(function () {
      function polyfillsLoader() {
        ${code}
      }

      if (${coreJs.test}) {
        var s = document.createElement('script');
        function onLoaded() {
          document.head.removeChild(s);
          polyfillsLoader();
        }
        s.src = "./${relativePolyfillPath(coreJs.path, cfg)}";
        s.onload = onLoaded;
        s.onerror = function () {
          console.error('[polyfills-loader] failed to load: ' + s.src + ' check the network tab for HTTP status.');
          onLoaded();
        }
        document.head.appendChild(s);
      } else {
        polyfillsLoader();
      }
     })();`;
    }
    else {
        code = `(function () { ${code} })();`;
    }
    if (cfg.minify) {
        const output = await terser_1.default.minify(code);
        if (!output || !output.code) {
            throw new Error('Could not minify loader.');
        }
        ({ code } = output);
    }
    else {
        const output = await core_1.transformAsync(code, { babelrc: false, configFile: false });
        if (!output || !output.code) {
            throw new Error('Could not prettify loader.');
        }
        ({ code } = output);
    }
    return { code, polyfillFiles: generatedFiles };
}
/**
 * Creates a loader script that executes immediately, loading the configured
 * polyfills and resources (app entrypoints, scripts etc.).
 */
Creates a loader script that executes immediately, loading the configured
polyfills and resources (app entrypoints, scripts etc.).
Creates a loader script that executes immediately loading the configured polyfills and resources ( app entrypoints scripts etc . ) .
async function createPolyfillsLoader(cfg) {
    let polyfillFiles = await createPolyfillsData_1.createPolyfillsData(cfg);
    const coreJs = polyfillFiles.find(pf => pf.name === 'core-js');
    polyfillFiles = polyfillFiles.filter(pf => pf !== coreJs);
    const { loadPolyfillsCode, generatedFiles } = createPolyfillsLoaderCode(cfg, polyfillFiles);
    let code = `
    ${createLoadScriptCode(cfg, polyfillFiles)}
    ${loadPolyfillsCode}
    ${createLoadFilesCode(cfg, polyfillFiles)}
  `;
    if (coreJs) {
        generatedFiles.push({
            type: utils_1.fileTypes.SCRIPT,
            path: coreJs.path,
            content: coreJs.content,
        });
        code = `(function () {
      function polyfillsLoader() {
        ${code}
      }
      if (${coreJs.test}) {
        var s = document.createElement('script');
        function onLoaded() {
          document.head.removeChild(s);
          polyfillsLoader();
        }
        s.src = "./${relativePolyfillPath(coreJs.path, cfg)}";
        s.onload = onLoaded;
        s.onerror = function () {
          console.error('[polyfills-loader] failed to load: ' + s.src + ' check the network tab for HTTP status.');
          onLoaded();
        }
        document.head.appendChild(s);
      } else {
        polyfillsLoader();
      }
     })();`;
    }
    else {
        code = `(function () { ${code} })();`;
    }
    if (cfg.minify) {
        const output = await terser_1.default.minify(code);
        if (!output || !output.code) {
            throw new Error('Could not minify loader.');
        }
        ({ code } = output);
    }
    else {
        const output = await core_1.transformAsync(code, { babelrc: false, configFile: false });
        if (!output || !output.code) {
            throw new Error('Could not prettify loader.');
        }
        ({ code } = output);
    }
    return { code, polyfillFiles: generatedFiles };
}
async function createPolyfillsLoader ( cfg ) { let polyfillFiles = await createPolyfillsData_1 . createPolyfillsData ( cfg ) ; const coreJs = polyfillFiles . find ( pf => pf . name === 'core-js' ) ; polyfillFiles = polyfillFiles . filter ( pf => pf !== coreJs ) ; const { loadPolyfillsCode , generatedFiles } = createPolyfillsLoaderCode ( cfg , polyfillFiles ) ; let code = ` ${ createLoadScriptCode ( cfg , polyfillFiles ) } ${ loadPolyfillsCode } ${ createLoadFilesCode ( cfg , polyfillFiles ) } ` ; if ( coreJs ) { generatedFiles . push ( { type : utils_1 . fileTypes . SCRIPT , path : coreJs . path , content : coreJs . content , } ) ; code = ` ${ code } ${ coreJs . test } ${ relativePolyfillPath ( coreJs . path , cfg ) } ` ; } else { code = ` ${ code } ` ; } if ( cfg . minify ) { const output = await terser_1 . default . minify ( code ) ; if ( ! output || ! output . code ) { throw new Error ( 'Could not minify loader.' ) ; } ( { code } = output ) ; } else { const output = await core_1 . transformAsync ( code , { babelrc : false , configFile : false } ) ; if ( ! output || ! output . code ) { throw new Error ( 'Could not prettify loader.' ) ; } ( { code } = output ) ; } return { code , polyfillFiles : generatedFiles } ; }
Creates a loader script that executes immediately, loading the configured
 polyfills and resources (app entrypoints, scripts etc.
Creates a loader script that executes immediately loading the configured polyfills and resources ( app entrypoints scripts etc .
// if core-js should be polyfilled, load it first and then the rest because most // polyfills rely on things like Promise to be already loaded