1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { getEntryRuntime } = require("./util/runtime");
|
9 |
|
10 |
|
11 |
|
12 | class FlagEntryExportAsUsedPlugin {
|
13 | constructor(nsObjectUsed, explanation) {
|
14 | this.nsObjectUsed = nsObjectUsed;
|
15 | this.explanation = explanation;
|
16 | }
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 |
|
23 | apply(compiler) {
|
24 | compiler.hooks.thisCompilation.tap(
|
25 | "FlagEntryExportAsUsedPlugin",
|
26 | compilation => {
|
27 | const moduleGraph = compilation.moduleGraph;
|
28 | compilation.hooks.seal.tap("FlagEntryExportAsUsedPlugin", () => {
|
29 | for (const [
|
30 | entryName,
|
31 | { dependencies: deps, options }
|
32 | ] of compilation.entries) {
|
33 | const runtime = getEntryRuntime(compilation, entryName, options);
|
34 | for (const dep of deps) {
|
35 | const module = moduleGraph.getModule(dep);
|
36 | if (module) {
|
37 | const exportsInfo = moduleGraph.getExportsInfo(module);
|
38 | if (this.nsObjectUsed) {
|
39 | exportsInfo.setUsedInUnknownWay(runtime);
|
40 | } else {
|
41 | exportsInfo.setAllKnownExportsUsed(runtime);
|
42 | }
|
43 | moduleGraph.addExtraReason(module, this.explanation);
|
44 | }
|
45 | }
|
46 | }
|
47 | });
|
48 | }
|
49 | );
|
50 | }
|
51 | }
|
52 |
|
53 | module.exports = FlagEntryExportAsUsedPlugin;
|