diff --git a/lib/compiler.js b/lib/compiler.js index 03da94d1..106a5ba8 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -33,11 +33,15 @@ class HtmlWebpackChildCompiler { * @type {Promise<{[templatePath: string]: { content: string, hash: string, entry: WebpackChunk }}>} */ this.compilationPromise; - /** * @type {Date} */ this.compilationStarted; + /** + * All file dependencies of the child compiler + * @type {string[]} + */ + this.fileDependencies = []; } /** @@ -120,6 +124,10 @@ class HtmlWebpackChildCompiler { const compiledTemplates = entries ? extractHelperFilesFromCompilation(mainCompilation, childCompilation, outputOptions.filename, entries) : []; + // Extract file dependencies + if (entries) { + this.fileDependencies = extractFileDependenciesFilesFromCompilation(entries); + } // Reject the promise if the childCompilation contains error if (childCompilation && childCompilation.errors && childCompilation.errors.length) { const errorDetails = childCompilation.errors.map(error => error.message + (error.error ? ':\n' + error.error : '')).join('\n'); @@ -181,6 +189,21 @@ function extractHelperFilesFromCompilation (mainCompilation, childCompilation, f return helperContents; } +/** + * Return all file dependencies from the given set of entries. + * @param {WebpackChunk[]} entries + * @returns {string[]} + */ +function extractFileDependenciesFilesFromCompilation (entries) { + const fileDependencies = new Map(); + entries.forEach((entry) => { + entry.entryModule.buildInfo.fileDependencies.forEach((fileDependency) => { + fileDependencies.set(fileDependency, true); + }); + }); + return Array.from(fileDependencies.keys()); +} + /** * @type {WeakMap}} */