1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const Dependency = require("../Dependency");
|
9 | const Template = require("../Template");
|
10 | const makeSerializable = require("../util/makeSerializable");
|
11 | const ModuleDependency = require("./ModuleDependency");
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | class WebpackIsIncludedDependency extends ModuleDependency {
|
21 | constructor(request, range) {
|
22 | super(request);
|
23 |
|
24 | this.weak = true;
|
25 | this.range = range;
|
26 | }
|
27 |
|
28 | |
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | getReferencedExports(moduleGraph, runtime) {
|
35 |
|
36 | return Dependency.NO_EXPORTS_REFERENCED;
|
37 | }
|
38 |
|
39 | get type() {
|
40 | return "__webpack_is_included__";
|
41 | }
|
42 | }
|
43 |
|
44 | makeSerializable(
|
45 | WebpackIsIncludedDependency,
|
46 | "webpack/lib/dependencies/WebpackIsIncludedDependency"
|
47 | );
|
48 |
|
49 | WebpackIsIncludedDependency.Template = class WebpackIsIncludedDependencyTemplate extends (
|
50 | ModuleDependency.Template
|
51 | ) {
|
52 | |
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 | apply(dependency, source, { runtimeTemplate, chunkGraph, moduleGraph }) {
|
59 | const dep = (dependency);
|
60 | const connection = moduleGraph.getConnection(dep);
|
61 | const included = connection
|
62 | ? chunkGraph.getNumberOfModuleChunks(connection.module) > 0
|
63 | : false;
|
64 | const comment = runtimeTemplate.outputOptions.pathinfo
|
65 | ? Template.toComment(
|
66 | `__webpack_is_included__ ${runtimeTemplate.requestShortener.shorten(
|
67 | dep.request
|
68 | )}`
|
69 | )
|
70 | : "";
|
71 |
|
72 | source.replace(
|
73 | dep.range[0],
|
74 | dep.range[1] - 1,
|
75 | `${comment}${JSON.stringify(included)}`
|
76 | );
|
77 | }
|
78 | };
|
79 |
|
80 | module.exports = WebpackIsIncludedDependency;
|