From d36033528ad5ae7edfe607dd5966dd95c4d61a1f Mon Sep 17 00:00:00 2001 From: Joe Boyle Date: Tue, 12 Dec 2023 08:34:54 -0500 Subject: [PATCH] Use template path instead of unique compiler ID --- lib/child-compiler.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/child-compiler.js b/lib/child-compiler.js index 8bea9bec..ea5760f3 100644 --- a/lib/child-compiler.js +++ b/lib/child-compiler.js @@ -13,7 +13,6 @@ /** @typedef {import("webpack").sources.Source} Source */ /** @typedef {{hash: string, entry: Chunk, content: string, assets: {[name: string]: { source: Source, info: import("webpack").AssetInfo }}}} ChildCompilationTemplateResult */ -let instanceId = 0; /** * The HtmlWebpackChildCompiler is a helper to allow reusing one childCompiler * for multiple HtmlWebpackPlugin instances to improve the compilation performance. @@ -24,8 +23,6 @@ class HtmlWebpackChildCompiler { * @param {string[]} templates */ constructor (templates) { - /** Id for this ChildCompiler */ - this.id = instanceId++; /** * @type {string[]} templateIds * The template array will allow us to keep track which input generated which output @@ -110,12 +107,12 @@ class HtmlWebpackChildCompiler { childCompiler.context = mainCompilation.compiler.context; // Generate output file names - const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${this.id}`); + const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${template}`); // Add all templates this.templates.forEach((template, index) => { - new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler); - new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler); + new EntryPlugin(childCompiler.context, 'data:text/javascript,__webpack_public_path__ = __webpack_base_uri__ = htmlWebpackPluginPublicPath;', `HtmlWebpackPlugin_${index}-${template}`).apply(childCompiler); + new EntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${template}`).apply(childCompiler); }); // The templates are compiled and executed by NodeJS - similar to server side rendering