* Function to generate HTML file. * * @private * @param {Compiler} compiler * @param {Compilation} compilation * @param {string} outputName * @param {CachedChildCompilation} childCompilerPlugin * @param {PreviousEmittedAssets} previousEmittedAssets * @param {{ value: string |
(
compiler,
compilation,
outputName,
childCompilerPlugin,
previousEmittedAssets,
assetJson,
callback,
)
| 1251 | * @param {(err?: Error) => void} callback |
| 1252 | */ |
| 1253 | generateHTML( |
| 1254 | compiler, |
| 1255 | compilation, |
| 1256 | outputName, |
| 1257 | childCompilerPlugin, |
| 1258 | previousEmittedAssets, |
| 1259 | assetJson, |
| 1260 | callback, |
| 1261 | ) { |
| 1262 | // Get all entry point names for this html file |
| 1263 | const entryNames = Array.from(compilation.entrypoints.keys()); |
| 1264 | const filteredEntryNames = this.filterEntryChunks( |
| 1265 | entryNames, |
| 1266 | this.options.chunks, |
| 1267 | this.options.excludeChunks, |
| 1268 | ); |
| 1269 | const sortedEntryNames = this.sortEntryChunks( |
| 1270 | filteredEntryNames, |
| 1271 | this.options.chunksSortMode, |
| 1272 | compilation, |
| 1273 | ); |
| 1274 | const templateResult = this.options.templateContent |
| 1275 | ? { mainCompilationHash: compilation.hash } |
| 1276 | : childCompilerPlugin.getCompilationEntryResult(this.options.template); |
| 1277 | |
| 1278 | if ("error" in templateResult) { |
| 1279 | compilation.errors.push( |
| 1280 | new Error( |
| 1281 | prettyError(templateResult.error, compiler.context).toString(), |
| 1282 | ), |
| 1283 | ); |
| 1284 | } |
| 1285 | |
| 1286 | // If the child compilation was not executed during a previous main compile run |
| 1287 | // it is a cached result |
| 1288 | const isCompilationCached = |
| 1289 | templateResult.mainCompilationHash !== compilation.hash; |
| 1290 | /** Generated file paths from the entry point names */ |
| 1291 | const assetsInformationByGroups = this.getAssetsInformationByGroups( |
| 1292 | compilation, |
| 1293 | outputName, |
| 1294 | sortedEntryNames, |
| 1295 | ); |
| 1296 | // If the template and the assets did not change we don't have to emit the html |
| 1297 | const newAssetJson = JSON.stringify( |
| 1298 | this.getAssetFiles(assetsInformationByGroups), |
| 1299 | ); |
| 1300 | |
| 1301 | if ( |
| 1302 | isCompilationCached && |
| 1303 | this.options.cache && |
| 1304 | assetJson.value === newAssetJson |
| 1305 | ) { |
| 1306 | previousEmittedAssets.forEach(({ name, source, info }) => { |
| 1307 | compilation.emitAsset(name, source, info); |
| 1308 | }); |
| 1309 | return callback(); |
| 1310 | } else { |
no test coverage detected