1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { getEntryRuntime, mergeRuntimeOwned } = require("./util/runtime");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | class FlagAllModulesAsUsedPlugin {
|
14 | constructor(explanation) {
|
15 | this.explanation = explanation;
|
16 | }
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | apply(compiler) {
|
24 | compiler.hooks.compilation.tap(
|
25 | "FlagAllModulesAsUsedPlugin",
|
26 | compilation => {
|
27 | const moduleGraph = compilation.moduleGraph;
|
28 | compilation.hooks.optimizeDependencies.tap(
|
29 | "FlagAllModulesAsUsedPlugin",
|
30 | modules => {
|
31 |
|
32 | let runtime = undefined;
|
33 | for (const [name, { options }] of compilation.entries) {
|
34 | runtime = mergeRuntimeOwned(
|
35 | runtime,
|
36 | getEntryRuntime(compilation, name, options)
|
37 | );
|
38 | }
|
39 | for (const module of modules) {
|
40 | const exportsInfo = moduleGraph.getExportsInfo(module);
|
41 | exportsInfo.setUsedInUnknownWay(runtime);
|
42 | moduleGraph.addExtraReason(module, this.explanation);
|
43 | if (module.factoryMeta === undefined) {
|
44 | module.factoryMeta = {};
|
45 | }
|
46 | module.factoryMeta.sideEffectFree = false;
|
47 | }
|
48 | }
|
49 | );
|
50 | }
|
51 | );
|
52 | }
|
53 | }
|
54 |
|
55 | module.exports = FlagAllModulesAsUsedPlugin;
|