webpack 4.1.0 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +719 -721
  2. package/bin/webpack.js +69 -10
  3. package/lib/APIPlugin.js +84 -84
  4. package/lib/AmdMainTemplatePlugin.js +75 -77
  5. package/lib/AsyncDependencyToInitialChunkError.js +21 -23
  6. package/lib/BannerPlugin.js +101 -101
  7. package/lib/Chunk.js +477 -469
  8. package/lib/ChunkTemplate.js +51 -53
  9. package/lib/Compilation.js +1858 -1851
  10. package/lib/Compiler.js +493 -478
  11. package/lib/ConcurrentCompilationError.js +19 -0
  12. package/lib/ContextModule.js +696 -685
  13. package/lib/ContextModuleFactory.js +245 -243
  14. package/lib/DefinePlugin.js +197 -197
  15. package/lib/DelegatedModule.js +101 -101
  16. package/lib/DependenciesBlockVariable.js +51 -52
  17. package/lib/Dependency.js +53 -52
  18. package/lib/DllModule.js +54 -54
  19. package/lib/DllModuleFactory.js +29 -29
  20. package/lib/EnvironmentPlugin.js +65 -67
  21. package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
  22. package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
  23. package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
  24. package/lib/ExternalModule.js +159 -159
  25. package/lib/FunctionModuleTemplatePlugin.js +98 -98
  26. package/lib/HotModuleReplacement.runtime.js +631 -631
  27. package/lib/HotModuleReplacementPlugin.js +407 -406
  28. package/lib/HotUpdateChunkTemplate.js +78 -80
  29. package/lib/JavascriptGenerator.js +228 -229
  30. package/lib/JavascriptModulesPlugin.js +184 -158
  31. package/lib/JsonGenerator.js +42 -42
  32. package/lib/MainTemplate.js +406 -402
  33. package/lib/Module.js +343 -340
  34. package/lib/ModuleBuildError.js +42 -42
  35. package/lib/ModuleError.js +28 -28
  36. package/lib/ModuleFilenameHelpers.js +166 -166
  37. package/lib/ModuleTemplate.js +77 -79
  38. package/lib/ModuleWarning.js +30 -30
  39. package/lib/MultiCompiler.js +271 -259
  40. package/lib/MultiModule.js +78 -75
  41. package/lib/MultiModuleFactory.js +23 -23
  42. package/lib/MultiWatching.js +38 -37
  43. package/lib/NoModeWarning.js +23 -21
  44. package/lib/NormalModule.js +478 -470
  45. package/lib/NormalModuleFactory.js +483 -481
  46. package/lib/OptionsDefaulter.js +80 -86
  47. package/lib/Parser.js +2074 -2071
  48. package/lib/ProgressPlugin.js +231 -231
  49. package/lib/RawModule.js +54 -55
  50. package/lib/RecordIdsPlugin.js +160 -160
  51. package/lib/RemovedPluginError.js +13 -13
  52. package/lib/ResolverFactory.js +64 -67
  53. package/lib/RuntimeTemplate.js +267 -297
  54. package/lib/SetVarMainTemplatePlugin.js +57 -57
  55. package/lib/SourceMapDevToolPlugin.js +302 -308
  56. package/lib/Stats.js +1234 -1212
  57. package/lib/Template.js +205 -205
  58. package/lib/TemplatedPathPlugin.js +170 -143
  59. package/lib/UmdMainTemplatePlugin.js +264 -269
  60. package/lib/Watching.js +193 -193
  61. package/lib/WebAssemblyParser.js +50 -54
  62. package/lib/WebpackOptionsApply.js +401 -401
  63. package/lib/WebpackOptionsDefaulter.js +337 -317
  64. package/lib/WebpackOptionsValidationError.js +316 -319
  65. package/lib/debug/ProfilingPlugin.js +409 -405
  66. package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
  67. package/lib/dependencies/AMDRequireContextDependency.js +20 -20
  68. package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
  69. package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
  70. package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
  71. package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
  72. package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
  73. package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
  74. package/lib/dependencies/ImportDependenciesBlock.js +17 -17
  75. package/lib/dependencies/ImportDependency.js +34 -34
  76. package/lib/dependencies/ImportEagerDependency.js +32 -32
  77. package/lib/dependencies/ImportParserPlugin.js +175 -179
  78. package/lib/dependencies/ImportWeakDependency.js +34 -34
  79. package/lib/dependencies/JsonExportsDependency.js +25 -25
  80. package/lib/dependencies/ModuleDependency.js +20 -20
  81. package/lib/dependencies/NullDependency.js +20 -20
  82. package/lib/dependencies/RequireContextDependency.js +22 -22
  83. package/lib/dependencies/RequireIncludeDependency.js +40 -40
  84. package/lib/dependencies/WebpackMissingModule.js +20 -22
  85. package/lib/node/NodeChunkTemplatePlugin.js +31 -31
  86. package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
  87. package/lib/node/NodeMainTemplatePlugin.js +320 -273
  88. package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
  89. package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
  90. package/lib/optimize/ConcatenatedModule.js +1364 -1366
  91. package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
  92. package/lib/optimize/SplitChunksPlugin.js +519 -491
  93. package/lib/performance/SizeLimitsPlugin.js +105 -105
  94. package/lib/util/TrackingSet.js +35 -35
  95. package/lib/util/objectToMap.js +10 -10
  96. package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
  97. package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
  98. package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
  99. package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
  100. package/lib/web/JsonpMainTemplatePlugin.js +425 -403
  101. package/lib/webpack.js +182 -179
  102. package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
  103. package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
  104. package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
  105. package/package.json +9 -8
  106. package/schemas/WebpackOptions.json +1973 -1951
  107. package/schemas/ajv.absolutePath.js +55 -29
  108. package/schemas/plugins/BannerPlugin.json +85 -85
  109. package/schemas/plugins/DllPlugin.json +28 -28
  110. package/schemas/plugins/DllReferencePlugin.json +99 -99
  111. package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
  112. package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
  113. package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
  114. package/schemas/plugins/WatchIgnorePlugin.json +16 -16
  115. package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
  116. package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
  117. package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
  118. package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
@@ -1,197 +1,197 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const ConstDependency = require("./dependencies/ConstDependency");
8
- const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9
- const ParserHelpers = require("./ParserHelpers");
10
- const NullFactory = require("./NullFactory");
11
-
12
- const stringifyObj = obj => {
13
- return (
14
- "Object({" +
15
- Object.keys(obj)
16
- .map(key => {
17
- const code = obj[key];
18
- return JSON.stringify(key) + ":" + toCode(code);
19
- })
20
- .join(",") +
21
- "})"
22
- );
23
- };
24
-
25
- const toCode = code => {
26
- if (code === null) return "null";
27
- else if (code === undefined) return "undefined";
28
- else if (code instanceof RegExp && code.toString) return code.toString();
29
- else if (typeof code === "function" && code.toString)
30
- return "(" + code.toString() + ")";
31
- else if (typeof code === "object") return stringifyObj(code);
32
- else return code + "";
33
- };
34
-
35
- class DefinePlugin {
36
- constructor(definitions) {
37
- this.definitions = definitions;
38
- }
39
-
40
- apply(compiler) {
41
- const definitions = this.definitions;
42
- compiler.hooks.compilation.tap(
43
- "DefinePlugin",
44
- (compilation, { normalModuleFactory }) => {
45
- compilation.dependencyFactories.set(ConstDependency, new NullFactory());
46
- compilation.dependencyTemplates.set(
47
- ConstDependency,
48
- new ConstDependency.Template()
49
- );
50
-
51
- const handler = parser => {
52
- const walkDefinitions = (definitions, prefix) => {
53
- Object.keys(definitions).forEach(key => {
54
- const code = definitions[key];
55
- if (
56
- code &&
57
- typeof code === "object" &&
58
- !(code instanceof RegExp)
59
- ) {
60
- walkDefinitions(code, prefix + key + ".");
61
- applyObjectDefine(prefix + key, code);
62
- return;
63
- }
64
- applyDefineKey(prefix, key);
65
- applyDefine(prefix + key, code);
66
- });
67
- };
68
-
69
- const applyDefineKey = (prefix, key) => {
70
- const splittedKey = key.split(".");
71
- splittedKey.slice(1).forEach((_, i) => {
72
- const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
73
- parser.hooks.canRename
74
- .for(fullKey)
75
- .tap("DefinePlugin", ParserHelpers.approve);
76
- });
77
- };
78
-
79
- const applyDefine = (key, code) => {
80
- const isTypeof = /^typeof\s+/.test(key);
81
- if (isTypeof) key = key.replace(/^typeof\s+/, "");
82
- let recurse = false;
83
- let recurseTypeof = false;
84
- code = toCode(code);
85
- if (!isTypeof) {
86
- parser.hooks.canRename
87
- .for(key)
88
- .tap("DefinePlugin", ParserHelpers.approve);
89
- parser.hooks.evaluateIdentifier
90
- .for(key)
91
- .tap("DefinePlugin", expr => {
92
- /**
93
- * this is needed in case there is a recursion in the DefinePlugin
94
- * to prevent an endless recursion
95
- * e.g.: new DefinePlugin({
96
- * "a": "b",
97
- * "b": "a"
98
- * });
99
- */
100
- if (recurse) return;
101
- recurse = true;
102
- const res = parser.evaluate(code);
103
- recurse = false;
104
- res.setRange(expr.range);
105
- return res;
106
- });
107
- parser.hooks.expression
108
- .for(key)
109
- .tap(
110
- "DefinePlugin",
111
- /__webpack_require__/.test(code)
112
- ? ParserHelpers.toConstantDependencyWithWebpackRequire(
113
- parser,
114
- code
115
- )
116
- : ParserHelpers.toConstantDependency(parser, code)
117
- );
118
- }
119
- const typeofCode = isTypeof ? code : "typeof (" + code + ")";
120
- parser.hooks.evaluateTypeof.for(key).tap("DefinePlugin", expr => {
121
- /**
122
- * this is needed in case there is a recursion in the DefinePlugin
123
- * to prevent an endless recursion
124
- * e.g.: new DefinePlugin({
125
- * "typeof a": "typeof b",
126
- * "typeof b": "typeof a"
127
- * });
128
- */
129
- if (recurseTypeof) return;
130
- recurseTypeof = true;
131
- const res = parser.evaluate(typeofCode);
132
- recurseTypeof = false;
133
- res.setRange(expr.range);
134
- return res;
135
- });
136
- parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
137
- const res = parser.evaluate(typeofCode);
138
- if (!res.isString()) return;
139
- return ParserHelpers.toConstantDependency(
140
- parser,
141
- JSON.stringify(res.string)
142
- ).bind(parser)(expr);
143
- });
144
- };
145
-
146
- const applyObjectDefine = (key, obj) => {
147
- const code = stringifyObj(obj);
148
- parser.hooks.canRename
149
- .for(key)
150
- .tap("DefinePlugin", ParserHelpers.approve);
151
- parser.hooks.evaluateIdentifier
152
- .for(key)
153
- .tap("DefinePlugin", expr =>
154
- new BasicEvaluatedExpression().setTruthy().setRange(expr.range)
155
- );
156
- parser.hooks.evaluateTypeof
157
- .for(key)
158
- .tap("DefinePlugin", ParserHelpers.evaluateToString("object"));
159
- parser.hooks.expression
160
- .for(key)
161
- .tap(
162
- "DefinePlugin",
163
- /__webpack_require__/.test(code)
164
- ? ParserHelpers.toConstantDependencyWithWebpackRequire(
165
- parser,
166
- code
167
- )
168
- : ParserHelpers.toConstantDependency(parser, code)
169
- );
170
- parser.hooks.typeof
171
- .for(key)
172
- .tap(
173
- "DefinePlugin",
174
- ParserHelpers.toConstantDependency(
175
- parser,
176
- JSON.stringify("object")
177
- )
178
- );
179
- };
180
-
181
- walkDefinitions(definitions, "");
182
- };
183
-
184
- normalModuleFactory.hooks.parser
185
- .for("javascript/auto")
186
- .tap("DefinePlugin", handler);
187
- normalModuleFactory.hooks.parser
188
- .for("javascript/dynamic")
189
- .tap("DefinePlugin", handler);
190
- normalModuleFactory.hooks.parser
191
- .for("javascript/esm")
192
- .tap("DefinePlugin", handler);
193
- }
194
- );
195
- }
196
- }
197
- module.exports = DefinePlugin;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const ConstDependency = require("./dependencies/ConstDependency");
8
+ const BasicEvaluatedExpression = require("./BasicEvaluatedExpression");
9
+ const ParserHelpers = require("./ParserHelpers");
10
+ const NullFactory = require("./NullFactory");
11
+
12
+ const stringifyObj = obj => {
13
+ return (
14
+ "Object({" +
15
+ Object.keys(obj)
16
+ .map(key => {
17
+ const code = obj[key];
18
+ return JSON.stringify(key) + ":" + toCode(code);
19
+ })
20
+ .join(",") +
21
+ "})"
22
+ );
23
+ };
24
+
25
+ const toCode = code => {
26
+ if (code === null) return "null";
27
+ else if (code === undefined) return "undefined";
28
+ else if (code instanceof RegExp && code.toString) return code.toString();
29
+ else if (typeof code === "function" && code.toString)
30
+ return "(" + code.toString() + ")";
31
+ else if (typeof code === "object") return stringifyObj(code);
32
+ else return code + "";
33
+ };
34
+
35
+ class DefinePlugin {
36
+ constructor(definitions) {
37
+ this.definitions = definitions;
38
+ }
39
+
40
+ apply(compiler) {
41
+ const definitions = this.definitions;
42
+ compiler.hooks.compilation.tap(
43
+ "DefinePlugin",
44
+ (compilation, { normalModuleFactory }) => {
45
+ compilation.dependencyFactories.set(ConstDependency, new NullFactory());
46
+ compilation.dependencyTemplates.set(
47
+ ConstDependency,
48
+ new ConstDependency.Template()
49
+ );
50
+
51
+ const handler = parser => {
52
+ const walkDefinitions = (definitions, prefix) => {
53
+ Object.keys(definitions).forEach(key => {
54
+ const code = definitions[key];
55
+ if (
56
+ code &&
57
+ typeof code === "object" &&
58
+ !(code instanceof RegExp)
59
+ ) {
60
+ walkDefinitions(code, prefix + key + ".");
61
+ applyObjectDefine(prefix + key, code);
62
+ return;
63
+ }
64
+ applyDefineKey(prefix, key);
65
+ applyDefine(prefix + key, code);
66
+ });
67
+ };
68
+
69
+ const applyDefineKey = (prefix, key) => {
70
+ const splittedKey = key.split(".");
71
+ splittedKey.slice(1).forEach((_, i) => {
72
+ const fullKey = prefix + splittedKey.slice(0, i + 1).join(".");
73
+ parser.hooks.canRename
74
+ .for(fullKey)
75
+ .tap("DefinePlugin", ParserHelpers.approve);
76
+ });
77
+ };
78
+
79
+ const applyDefine = (key, code) => {
80
+ const isTypeof = /^typeof\s+/.test(key);
81
+ if (isTypeof) key = key.replace(/^typeof\s+/, "");
82
+ let recurse = false;
83
+ let recurseTypeof = false;
84
+ code = toCode(code);
85
+ if (!isTypeof) {
86
+ parser.hooks.canRename
87
+ .for(key)
88
+ .tap("DefinePlugin", ParserHelpers.approve);
89
+ parser.hooks.evaluateIdentifier
90
+ .for(key)
91
+ .tap("DefinePlugin", expr => {
92
+ /**
93
+ * this is needed in case there is a recursion in the DefinePlugin
94
+ * to prevent an endless recursion
95
+ * e.g.: new DefinePlugin({
96
+ * "a": "b",
97
+ * "b": "a"
98
+ * });
99
+ */
100
+ if (recurse) return;
101
+ recurse = true;
102
+ const res = parser.evaluate(code);
103
+ recurse = false;
104
+ res.setRange(expr.range);
105
+ return res;
106
+ });
107
+ parser.hooks.expression
108
+ .for(key)
109
+ .tap(
110
+ "DefinePlugin",
111
+ /__webpack_require__/.test(code)
112
+ ? ParserHelpers.toConstantDependencyWithWebpackRequire(
113
+ parser,
114
+ code
115
+ )
116
+ : ParserHelpers.toConstantDependency(parser, code)
117
+ );
118
+ }
119
+ const typeofCode = isTypeof ? code : "typeof (" + code + ")";
120
+ parser.hooks.evaluateTypeof.for(key).tap("DefinePlugin", expr => {
121
+ /**
122
+ * this is needed in case there is a recursion in the DefinePlugin
123
+ * to prevent an endless recursion
124
+ * e.g.: new DefinePlugin({
125
+ * "typeof a": "typeof b",
126
+ * "typeof b": "typeof a"
127
+ * });
128
+ */
129
+ if (recurseTypeof) return;
130
+ recurseTypeof = true;
131
+ const res = parser.evaluate(typeofCode);
132
+ recurseTypeof = false;
133
+ res.setRange(expr.range);
134
+ return res;
135
+ });
136
+ parser.hooks.typeof.for(key).tap("DefinePlugin", expr => {
137
+ const res = parser.evaluate(typeofCode);
138
+ if (!res.isString()) return;
139
+ return ParserHelpers.toConstantDependency(
140
+ parser,
141
+ JSON.stringify(res.string)
142
+ ).bind(parser)(expr);
143
+ });
144
+ };
145
+
146
+ const applyObjectDefine = (key, obj) => {
147
+ const code = stringifyObj(obj);
148
+ parser.hooks.canRename
149
+ .for(key)
150
+ .tap("DefinePlugin", ParserHelpers.approve);
151
+ parser.hooks.evaluateIdentifier
152
+ .for(key)
153
+ .tap("DefinePlugin", expr =>
154
+ new BasicEvaluatedExpression().setTruthy().setRange(expr.range)
155
+ );
156
+ parser.hooks.evaluateTypeof
157
+ .for(key)
158
+ .tap("DefinePlugin", ParserHelpers.evaluateToString("object"));
159
+ parser.hooks.expression
160
+ .for(key)
161
+ .tap(
162
+ "DefinePlugin",
163
+ /__webpack_require__/.test(code)
164
+ ? ParserHelpers.toConstantDependencyWithWebpackRequire(
165
+ parser,
166
+ code
167
+ )
168
+ : ParserHelpers.toConstantDependency(parser, code)
169
+ );
170
+ parser.hooks.typeof
171
+ .for(key)
172
+ .tap(
173
+ "DefinePlugin",
174
+ ParserHelpers.toConstantDependency(
175
+ parser,
176
+ JSON.stringify("object")
177
+ )
178
+ );
179
+ };
180
+
181
+ walkDefinitions(definitions, "");
182
+ };
183
+
184
+ normalModuleFactory.hooks.parser
185
+ .for("javascript/auto")
186
+ .tap("DefinePlugin", handler);
187
+ normalModuleFactory.hooks.parser
188
+ .for("javascript/dynamic")
189
+ .tap("DefinePlugin", handler);
190
+ normalModuleFactory.hooks.parser
191
+ .for("javascript/esm")
192
+ .tap("DefinePlugin", handler);
193
+ }
194
+ );
195
+ }
196
+ }
197
+ module.exports = DefinePlugin;
@@ -1,101 +1,101 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- */
5
- "use strict";
6
-
7
- const Module = require("./Module");
8
- const OriginalSource = require("webpack-sources").OriginalSource;
9
- const RawSource = require("webpack-sources").RawSource;
10
- const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
11
- const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
- const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
13
-
14
- class DelegatedModule extends Module {
15
- constructor(sourceRequest, data, type, userRequest, originalRequest) {
16
- super("javascript/dynamic", null);
17
-
18
- // Info from Factory
19
- this.sourceRequest = sourceRequest;
20
- this.request = data.id;
21
- this.type = type;
22
- this.userRequest = userRequest;
23
- this.originalRequest = originalRequest;
24
- this.delegateData = data;
25
- }
26
-
27
- libIdent(options) {
28
- return typeof this.originalRequest === "string"
29
- ? this.originalRequest
30
- : this.originalRequest.libIdent(options);
31
- }
32
-
33
- identifier() {
34
- return `delegated ${JSON.stringify(this.request)} from ${
35
- this.sourceRequest
36
- }`;
37
- }
38
-
39
- readableIdentifier() {
40
- return `delegated ${this.userRequest} from ${this.sourceRequest}`;
41
- }
42
-
43
- needRebuild() {
44
- return false;
45
- }
46
-
47
- build(options, compilation, resolver, fs, callback) {
48
- this.built = true;
49
- this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
50
- this.buildInfo = {};
51
- this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
52
- this.addDependency(
53
- new DelegatedExportsDependency(this, this.delegateData.exports || true)
54
- );
55
- callback();
56
- }
57
-
58
- source(depTemplates, runtime) {
59
- const dep = this.dependencies[0];
60
- const sourceModule = dep.module;
61
- let str;
62
-
63
- if (!sourceModule) {
64
- str = WebpackMissingModule.moduleCode(this.sourceRequest);
65
- } else {
66
- str = `module.exports = (${runtime.moduleExports({
67
- module: sourceModule,
68
- request: dep.request
69
- })})`;
70
-
71
- switch (this.type) {
72
- case "require":
73
- str += `(${JSON.stringify(this.request)})`;
74
- break;
75
- case "object":
76
- str += `[${JSON.stringify(this.request)}]`;
77
- break;
78
- }
79
-
80
- str += ";";
81
- }
82
-
83
- if (this.useSourceMap) {
84
- return new OriginalSource(str, this.identifier());
85
- } else {
86
- return new RawSource(str);
87
- }
88
- }
89
-
90
- size() {
91
- return 42;
92
- }
93
-
94
- updateHash(hash) {
95
- hash.update(this.type);
96
- hash.update(JSON.stringify(this.request));
97
- super.updateHash(hash);
98
- }
99
- }
100
-
101
- module.exports = DelegatedModule;
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict";
6
+
7
+ const { OriginalSource, RawSource } = require("webpack-sources");
8
+
9
+ const Module = require("./Module");
10
+ const WebpackMissingModule = require("./dependencies/WebpackMissingModule");
11
+ const DelegatedSourceDependency = require("./dependencies/DelegatedSourceDependency");
12
+ const DelegatedExportsDependency = require("./dependencies/DelegatedExportsDependency");
13
+
14
+ class DelegatedModule extends Module {
15
+ constructor(sourceRequest, data, type, userRequest, originalRequest) {
16
+ super("javascript/dynamic", null);
17
+
18
+ // Info from Factory
19
+ this.sourceRequest = sourceRequest;
20
+ this.request = data.id;
21
+ this.type = type;
22
+ this.userRequest = userRequest;
23
+ this.originalRequest = originalRequest;
24
+ this.delegateData = data;
25
+ }
26
+
27
+ libIdent(options) {
28
+ return typeof this.originalRequest === "string"
29
+ ? this.originalRequest
30
+ : this.originalRequest.libIdent(options);
31
+ }
32
+
33
+ identifier() {
34
+ return `delegated ${JSON.stringify(this.request)} from ${
35
+ this.sourceRequest
36
+ }`;
37
+ }
38
+
39
+ readableIdentifier() {
40
+ return `delegated ${this.userRequest} from ${this.sourceRequest}`;
41
+ }
42
+
43
+ needRebuild() {
44
+ return false;
45
+ }
46
+
47
+ build(options, compilation, resolver, fs, callback) {
48
+ this.built = true;
49
+ this.buildMeta = Object.assign({}, this.delegateData.buildMeta);
50
+ this.buildInfo = {};
51
+ this.addDependency(new DelegatedSourceDependency(this.sourceRequest));
52
+ this.addDependency(
53
+ new DelegatedExportsDependency(this, this.delegateData.exports || true)
54
+ );
55
+ callback();
56
+ }
57
+
58
+ source(depTemplates, runtime) {
59
+ const dep = this.dependencies[0];
60
+ const sourceModule = dep.module;
61
+ let str;
62
+
63
+ if (!sourceModule) {
64
+ str = WebpackMissingModule.moduleCode(this.sourceRequest);
65
+ } else {
66
+ str = `module.exports = (${runtime.moduleExports({
67
+ module: sourceModule,
68
+ request: dep.request
69
+ })})`;
70
+
71
+ switch (this.type) {
72
+ case "require":
73
+ str += `(${JSON.stringify(this.request)})`;
74
+ break;
75
+ case "object":
76
+ str += `[${JSON.stringify(this.request)}]`;
77
+ break;
78
+ }
79
+
80
+ str += ";";
81
+ }
82
+
83
+ if (this.useSourceMap) {
84
+ return new OriginalSource(str, this.identifier());
85
+ } else {
86
+ return new RawSource(str);
87
+ }
88
+ }
89
+
90
+ size() {
91
+ return 42;
92
+ }
93
+
94
+ updateHash(hash) {
95
+ hash.update(this.type);
96
+ hash.update(JSON.stringify(this.request));
97
+ super.updateHash(hash);
98
+ }
99
+ }
100
+
101
+ module.exports = DelegatedModule;