1 |
3a515b92
|
cagy
|
/*
|
2 |
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
3 |
|
|
Author Tobias Koppers @sokra
|
4 |
|
|
*/
|
5 |
|
|
"use strict";
|
6 |
|
|
|
7 |
|
|
class FlagInitialModulesAsUsedPlugin {
|
8 |
|
|
constructor(explanation) {
|
9 |
|
|
this.explanation = explanation;
|
10 |
|
|
}
|
11 |
|
|
|
12 |
|
|
apply(compiler) {
|
13 |
|
|
compiler.hooks.compilation.tap(
|
14 |
|
|
"FlagInitialModulesAsUsedPlugin",
|
15 |
|
|
compilation => {
|
16 |
|
|
compilation.hooks.afterOptimizeChunks.tap(
|
17 |
|
|
"FlagInitialModulesAsUsedPlugin",
|
18 |
|
|
chunks => {
|
19 |
|
|
for (const chunk of chunks) {
|
20 |
|
|
if (!chunk.isOnlyInitial()) {
|
21 |
|
|
return;
|
22 |
|
|
}
|
23 |
|
|
for (const module of chunk.modulesIterable) {
|
24 |
|
|
module.used = true;
|
25 |
|
|
module.usedExports = true;
|
26 |
|
|
module.addReason(null, null, this.explanation);
|
27 |
|
|
}
|
28 |
|
|
}
|
29 |
|
|
}
|
30 |
|
|
);
|
31 |
|
|
}
|
32 |
|
|
);
|
33 |
|
|
}
|
34 |
|
|
}
|
35 |
|
|
|
36 |
|
|
module.exports = FlagInitialModulesAsUsedPlugin;
|