Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async output => {
const { emittedFiles = [], webpackStats } = output;
if (!output.success || !i18n.shouldInline) {
return output as ServerBuilderOutput;
}
if (!webpackStats) {
throw new Error('Webpack stats build result is required.');
}
const outputPaths = ensureOutputPaths(baseOutputPath, i18n);
/*const success = */
await i18nInlineEmittedFiles(
context,
emittedFiles,
i18n,
baseOutputPath,
Array.from(outputPaths.values()),
[],
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
if (!output.success) {
return output as ServerBuilderOutput;
}
let noModuleFiles: EmittedFiles[] | undefined;
let moduleFiles: EmittedFiles[] | undefined;
let files: EmittedFiles[] | undefined;
const scriptsEntryPointName = normalizeExtraEntryPoints(
options.scripts || [],
'scripts',
).map(x => x.bundleName);
if (isDifferentialLoadingNeeded && options.watch) {
moduleFiles = emittedFiles;
files = moduleFiles.filter(
x => x.extension === '.css' || (x.name && scriptsEntryPointName.includes(x.name)),
);
if (i18n.shouldInline) {
const success = await i18nInlineEmittedFiles(
context,
emittedFiles,
i18n,
baseOutputPath,
Array.from(outputPaths.values()),
scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
if (!success) {
return finalize(false);
}
}
} else if (isDifferentialLoadingNeeded) {
(webpackStats && webpackStats.hash) || '',
Date.now() - startTime,
true,
);
context.logger.info(bundleInfoText);
if (webpackStats && webpackStats.warnings.length > 0) {
context.logger.warn(statsWarningsToString(webpackStats, { colors: true }));
}
if (webpackStats && webpackStats.errors.length > 0) {
context.logger.error(statsErrorsToString(webpackStats, { colors: true }));
}
} else {
files = emittedFiles.filter(x => x.name !== 'polyfills-es5');
noModuleFiles = emittedFiles.filter(x => x.name === 'polyfills-es5');
if (i18n.shouldInline) {
const success = await i18nInlineEmittedFiles(
context,
emittedFiles,
i18n,
baseOutputPath,
Array.from(outputPaths.values()),
scriptsEntryPointName,
// tslint:disable-next-line: no-non-null-assertion
webpackStats.outputPath!,
target <= ScriptTarget.ES5,
options.i18nMissingTranslation,
);
if (!success) {
return finalize(false);
}
}
}