Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function injectIntoIndexHTML(pluginConfig, inputIndexHTML, entries, legacyEntries) {
/**
* Inject output files, loader script and polyfills into index.html
*/
if (pluginConfig.inject) {
const result = createIndexHTML(inputIndexHTML, {
...pluginConfig,
entries,
legacyEntries,
});
return [{ path: pluginConfig.indexFilename, content: result.indexHTML }, ...result.files];
}
/**
* If injection is disabled the user takes control, probably with it's own template.
*/
const serialized = serialize(inputIndexHTML);
return [{ path: pluginConfig.indexFilename, content: minifyIndexHTML(serialized) }];
}
});
localBaseIndex = parse(templateString);
} else {
/**
* If there is no user defined template the entrypoint was an index.html, and we use that as the base
* for our output. We need to clone it to avoid mutating the baseIndex variable.
*/
localBaseIndex = cloneAST(baseIndex);
}
/** @type {string} */
let finalIndexHTML;
/** Inject generated output into index.html */
if (config.inject) {
const generateResult = createIndexHTML(localBaseIndex, {
...config,
entries: { type: 'script', files: entries },
legacyEntries: legacyEntries ? { type: 'script', files: legacyEntries } : undefined,
});
finalIndexHTML = generateResult.indexHTML;
if (config.multiIndex && config.multiIndex.transformIndex) {
finalIndexHTML = config.multiIndex.transformIndex(
finalIndexHTML,
variation.toString(),
variation === VARIATION_FALLBACK,
);
}
generateResult.files.forEach(file => {
compilation.assets[file.path] = {