Skip to content

Commit bbc07a3

Browse files
committedJun 21, 2018
feat(compiler): Add file dependencies
1 parent f29ae88 commit bbc07a3

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed
 

‎lib/compiler.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,15 @@ class HtmlWebpackChildCompiler {
3333
* @type {Promise<{[templatePath: string]: { content: string, hash: string, entry: WebpackChunk }}>}
3434
*/
3535
this.compilationPromise;
36-
3736
/**
3837
* @type {Date}
3938
*/
4039
this.compilationStarted;
40+
/**
41+
* All file dependencies of the child compiler
42+
* @type {string[]}
43+
*/
44+
this.fileDependencies = [];
4145
}
4246

4347
/**
@@ -120,6 +124,10 @@ class HtmlWebpackChildCompiler {
120124
const compiledTemplates = entries
121125
? extractHelperFilesFromCompilation(mainCompilation, childCompilation, outputOptions.filename, entries)
122126
: [];
127+
// Extract file dependencies
128+
if (entries) {
129+
this.fileDependencies = extractFileDependenciesFilesFromCompilation(entries);
130+
}
123131
// Reject the promise if the childCompilation contains error
124132
if (childCompilation && childCompilation.errors && childCompilation.errors.length) {
125133
const errorDetails = childCompilation.errors.map(error => error.message + (error.error ? ':\n' + error.error : '')).join('\n');
@@ -181,6 +189,21 @@ function extractHelperFilesFromCompilation (mainCompilation, childCompilation, f
181189
return helperContents;
182190
}
183191

192+
/**
193+
* Return all file dependencies from the given set of entries.
194+
* @param {WebpackChunk[]} entries
195+
* @returns {string[]}
196+
*/
197+
function extractFileDependenciesFilesFromCompilation (entries) {
198+
const fileDependencies = new Map();
199+
entries.forEach((entry) => {
200+
entry.entryModule.buildInfo.fileDependencies.forEach((fileDependency) => {
201+
fileDependencies.set(fileDependency, true);
202+
});
203+
});
204+
return Array.from(fileDependencies.keys());
205+
}
206+
184207
/**
185208
* @type {WeakMap<WebpackCompiler, HtmlWebpackChildCompiler>}}
186209
*/

0 commit comments

Comments
 (0)
Please sign in to comment.