Skip to content

Commit

Permalink
refactor: use compilation ids instead of template paths
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Feb 3, 2021
1 parent 1c1fdb9 commit aa64b82
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/child-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const LibraryTemplatePlugin = require('webpack/lib/LibraryTemplatePlugin');
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin');
const Compilation = require('webpack').Compilation;

let instanceId = 0;
/**
* The HtmlWebpackChildCompiler is a helper to allow reusing one childCompiler
* for multiple HtmlWebpackPlugin instances to improve the compilation performance.
Expand All @@ -28,6 +29,8 @@ 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 @@ -102,11 +105,11 @@ class HtmlWebpackChildCompiler {
new LoaderTargetPlugin('node').apply(childCompiler);

// Generate output file names
const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${template}`);
const temporaryTemplateNames = this.templates.map((template, index) => `__child-HtmlWebpackPlugin_${index}-${this.id}`);

// Add all templates
this.templates.forEach((template, index) => {
new SingleEntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${template}`).apply(childCompiler);
new SingleEntryPlugin(childCompiler.context, template, `HtmlWebpackPlugin_${index}-${this.id}`).apply(childCompiler);
});

this.compilationStartedTimestamp = new Date().getTime();
Expand Down

0 comments on commit aa64b82

Please # to comment.