Skip to content

Commit

Permalink
Use template path instead of unique compiler ID
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsjoe committed Dec 12, 2023
1 parent 318cd4d commit d360335
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions lib/child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d360335

Please sign in to comment.