Skip to content

Commit

Permalink
feat(compiler): Add file dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jantimon committed Jun 21, 2018
1 parent f29ae88 commit bbc07a3
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/compiler.js
Expand Up @@ -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 = [];
}

/**
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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<WebpackCompiler, HtmlWebpackChildCompiler>}}
*/
Expand Down

0 comments on commit bbc07a3

Please sign in to comment.