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.
- package/README.md +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
package/lib/MainTemplate.js
CHANGED
@@ -1,402 +1,406 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
const
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
//
|
22
|
-
// __webpack_require__.
|
23
|
-
// __webpack_require__.
|
24
|
-
// __webpack_require__.
|
25
|
-
// __webpack_require__.
|
26
|
-
// __webpack_require__.
|
27
|
-
// __webpack_require__.
|
28
|
-
// __webpack_require__.
|
29
|
-
// __webpack_require__.
|
30
|
-
// __webpack_require__.
|
31
|
-
// __webpack_require__.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
"
|
45
|
-
|
46
|
-
|
47
|
-
"
|
48
|
-
"
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
"
|
54
|
-
"
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
"
|
60
|
-
"
|
61
|
-
|
62
|
-
|
63
|
-
"
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
"
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
"
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
"
|
86
|
-
"
|
87
|
-
|
88
|
-
|
89
|
-
"
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
(
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
source
|
124
|
-
|
125
|
-
);
|
126
|
-
source.add("/******/
|
127
|
-
source.add(
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
"//
|
155
|
-
"
|
156
|
-
Template.indent(
|
157
|
-
"}
|
158
|
-
"",
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
"
|
176
|
-
]),
|
177
|
-
"}"
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
"
|
193
|
-
"
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
buf.push(
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
buf.push("");
|
224
|
-
buf.push("// expose the
|
225
|
-
buf.push(`${this.requireFn}.
|
226
|
-
|
227
|
-
buf.push("");
|
228
|
-
buf.push("//
|
229
|
-
buf.push(`${this.requireFn}.
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
buf.push(
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
buf.push(
|
262
|
-
buf.push(
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
buf.push(
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
buf.push(
|
319
|
-
buf.push("
|
320
|
-
buf.push("");
|
321
|
-
buf.push(
|
322
|
-
|
323
|
-
);
|
324
|
-
buf.push("");
|
325
|
-
buf.push(
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
return
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
varModule
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
}
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
this.
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const {
|
8
|
+
ConcatSource,
|
9
|
+
OriginalSource,
|
10
|
+
PrefixSource,
|
11
|
+
RawSource
|
12
|
+
} = require("webpack-sources");
|
13
|
+
const {
|
14
|
+
Tapable,
|
15
|
+
SyncWaterfallHook,
|
16
|
+
SyncHook,
|
17
|
+
SyncBailHook
|
18
|
+
} = require("tapable");
|
19
|
+
const Template = require("./Template");
|
20
|
+
|
21
|
+
// require function shortcuts:
|
22
|
+
// __webpack_require__.s = the module id of the entry point
|
23
|
+
// __webpack_require__.c = the module cache
|
24
|
+
// __webpack_require__.m = the module functions
|
25
|
+
// __webpack_require__.p = the bundle public path
|
26
|
+
// __webpack_require__.i = the identity function used for harmony imports
|
27
|
+
// __webpack_require__.e = the chunk ensure function
|
28
|
+
// __webpack_require__.d = the exported property define getter function
|
29
|
+
// __webpack_require__.o = Object.prototype.hasOwnProperty.call
|
30
|
+
// __webpack_require__.r = define compatibility on export
|
31
|
+
// __webpack_require__.n = compatibility get default export
|
32
|
+
// __webpack_require__.h = the webpack hash
|
33
|
+
// __webpack_require__.w = an object containing all installed WebAssembly.Modules keys by module id
|
34
|
+
// __webpack_require__.oe = the uncaught error handler for the webpack runtime
|
35
|
+
// __webpack_require__.nc = the script nonce
|
36
|
+
|
37
|
+
module.exports = class MainTemplate extends Tapable {
|
38
|
+
constructor(outputOptions) {
|
39
|
+
super();
|
40
|
+
this.outputOptions = outputOptions || {};
|
41
|
+
this.hooks = {
|
42
|
+
renderManifest: new SyncWaterfallHook(["result", "options"]),
|
43
|
+
modules: new SyncWaterfallHook([
|
44
|
+
"modules",
|
45
|
+
"chunk",
|
46
|
+
"hash",
|
47
|
+
"moduleTemplate",
|
48
|
+
"dependencyTemplates"
|
49
|
+
]),
|
50
|
+
moduleObj: new SyncWaterfallHook([
|
51
|
+
"source",
|
52
|
+
"chunk",
|
53
|
+
"hash",
|
54
|
+
"moduleIdExpression"
|
55
|
+
]),
|
56
|
+
requireEnsure: new SyncWaterfallHook([
|
57
|
+
"source",
|
58
|
+
"chunk",
|
59
|
+
"hash",
|
60
|
+
"chunkIdExpression"
|
61
|
+
]),
|
62
|
+
bootstrap: new SyncWaterfallHook([
|
63
|
+
"source",
|
64
|
+
"chunk",
|
65
|
+
"hash",
|
66
|
+
"moduleTemplate",
|
67
|
+
"dependencyTemplates"
|
68
|
+
]),
|
69
|
+
localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
70
|
+
require: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
71
|
+
requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
72
|
+
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
73
|
+
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
74
|
+
render: new SyncWaterfallHook([
|
75
|
+
"source",
|
76
|
+
"chunk",
|
77
|
+
"hash",
|
78
|
+
"moduleTemplate",
|
79
|
+
"dependencyTemplates"
|
80
|
+
]),
|
81
|
+
renderWithEntry: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
82
|
+
moduleRequire: new SyncWaterfallHook([
|
83
|
+
"source",
|
84
|
+
"chunk",
|
85
|
+
"hash",
|
86
|
+
"moduleIdExpression"
|
87
|
+
]),
|
88
|
+
addModule: new SyncWaterfallHook([
|
89
|
+
"source",
|
90
|
+
"chunk",
|
91
|
+
"hash",
|
92
|
+
"moduleIdExpression",
|
93
|
+
"moduleExpression"
|
94
|
+
]),
|
95
|
+
currentHash: new SyncWaterfallHook(["source", "requestedLength"]),
|
96
|
+
assetPath: new SyncWaterfallHook(["path", "options"]),
|
97
|
+
hash: new SyncHook(["hash"]),
|
98
|
+
hashForChunk: new SyncHook(["hash", "chunk"]),
|
99
|
+
globalHashPaths: new SyncWaterfallHook(["paths"]),
|
100
|
+
globalHash: new SyncBailHook(["chunk", "paths"]),
|
101
|
+
|
102
|
+
// TODO this should be moved somewhere else
|
103
|
+
// It's weird here
|
104
|
+
hotBootstrap: new SyncWaterfallHook(["source", "chunk", "hash"])
|
105
|
+
};
|
106
|
+
this.hooks.startup.tap("MainTemplate", (source, chunk, hash) => {
|
107
|
+
const buf = [];
|
108
|
+
if (chunk.entryModule) {
|
109
|
+
buf.push("// Load entry module and return exports");
|
110
|
+
buf.push(
|
111
|
+
`return ${this.renderRequireFunctionForModule(
|
112
|
+
hash,
|
113
|
+
chunk,
|
114
|
+
JSON.stringify(chunk.entryModule.id)
|
115
|
+
)}(${this.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`
|
116
|
+
);
|
117
|
+
}
|
118
|
+
return Template.asString(buf);
|
119
|
+
});
|
120
|
+
this.hooks.render.tap(
|
121
|
+
"MainTemplate",
|
122
|
+
(bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
|
123
|
+
const source = new ConcatSource();
|
124
|
+
source.add("/******/ (function(modules) { // webpackBootstrap\n");
|
125
|
+
source.add(new PrefixSource("/******/", bootstrapSource));
|
126
|
+
source.add("/******/ })\n");
|
127
|
+
source.add(
|
128
|
+
"/************************************************************************/\n"
|
129
|
+
);
|
130
|
+
source.add("/******/ (");
|
131
|
+
source.add(
|
132
|
+
this.hooks.modules.call(
|
133
|
+
new RawSource(""),
|
134
|
+
chunk,
|
135
|
+
hash,
|
136
|
+
moduleTemplate,
|
137
|
+
dependencyTemplates
|
138
|
+
)
|
139
|
+
);
|
140
|
+
source.add(")");
|
141
|
+
return source;
|
142
|
+
}
|
143
|
+
);
|
144
|
+
this.hooks.localVars.tap("MainTemplate", (source, chunk, hash) => {
|
145
|
+
return Template.asString([
|
146
|
+
source,
|
147
|
+
"// The module cache",
|
148
|
+
"var installedModules = {};"
|
149
|
+
]);
|
150
|
+
});
|
151
|
+
this.hooks.require.tap("MainTemplate", (source, chunk, hash) => {
|
152
|
+
return Template.asString([
|
153
|
+
source,
|
154
|
+
"// Check if module is in cache",
|
155
|
+
"if(installedModules[moduleId]) {",
|
156
|
+
Template.indent("return installedModules[moduleId].exports;"),
|
157
|
+
"}",
|
158
|
+
"// Create a new module (and put it into the cache)",
|
159
|
+
"var module = installedModules[moduleId] = {",
|
160
|
+
Template.indent(this.hooks.moduleObj.call("", chunk, hash, "moduleId")),
|
161
|
+
"};",
|
162
|
+
"",
|
163
|
+
Template.asString(
|
164
|
+
outputOptions.strictModuleExceptionHandling
|
165
|
+
? [
|
166
|
+
"// Execute the module function",
|
167
|
+
"var threw = true;",
|
168
|
+
"try {",
|
169
|
+
Template.indent([
|
170
|
+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
|
171
|
+
hash,
|
172
|
+
chunk,
|
173
|
+
"moduleId"
|
174
|
+
)});`,
|
175
|
+
"threw = false;"
|
176
|
+
]),
|
177
|
+
"} finally {",
|
178
|
+
Template.indent([
|
179
|
+
"if(threw) delete installedModules[moduleId];"
|
180
|
+
]),
|
181
|
+
"}"
|
182
|
+
]
|
183
|
+
: [
|
184
|
+
"// Execute the module function",
|
185
|
+
`modules[moduleId].call(module.exports, module, module.exports, ${this.renderRequireFunctionForModule(
|
186
|
+
hash,
|
187
|
+
chunk,
|
188
|
+
"moduleId"
|
189
|
+
)});`
|
190
|
+
]
|
191
|
+
),
|
192
|
+
"",
|
193
|
+
"// Flag the module as loaded",
|
194
|
+
"module.l = true;",
|
195
|
+
"",
|
196
|
+
"// Return the exports of the module",
|
197
|
+
"return module.exports;"
|
198
|
+
]);
|
199
|
+
});
|
200
|
+
this.hooks.moduleObj.tap(
|
201
|
+
"MainTemplate",
|
202
|
+
(source, chunk, hash, varModuleId) => {
|
203
|
+
return Template.asString(["i: moduleId,", "l: false,", "exports: {}"]);
|
204
|
+
}
|
205
|
+
);
|
206
|
+
this.hooks.requireExtensions.tap("MainTemplate", (source, chunk, hash) => {
|
207
|
+
const buf = [];
|
208
|
+
const chunkMaps = chunk.getChunkMaps();
|
209
|
+
// Check if there are non initial chunks which need to be imported using require-ensure
|
210
|
+
if (Object.keys(chunkMaps.hash).length) {
|
211
|
+
buf.push("// This file contains only the entry chunk.");
|
212
|
+
buf.push("// The chunk loading function for additional chunks");
|
213
|
+
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
|
214
|
+
buf.push(Template.indent("var promises = [];"));
|
215
|
+
buf.push(
|
216
|
+
Template.indent(
|
217
|
+
this.hooks.requireEnsure.call("", chunk, hash, "chunkId")
|
218
|
+
)
|
219
|
+
);
|
220
|
+
buf.push(Template.indent("return Promise.all(promises);"));
|
221
|
+
buf.push("};");
|
222
|
+
}
|
223
|
+
buf.push("");
|
224
|
+
buf.push("// expose the modules object (__webpack_modules__)");
|
225
|
+
buf.push(`${this.requireFn}.m = modules;`);
|
226
|
+
|
227
|
+
buf.push("");
|
228
|
+
buf.push("// expose the module cache");
|
229
|
+
buf.push(`${this.requireFn}.c = installedModules;`);
|
230
|
+
|
231
|
+
buf.push("");
|
232
|
+
buf.push("// define getter function for harmony exports");
|
233
|
+
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
|
234
|
+
buf.push(
|
235
|
+
Template.indent([
|
236
|
+
`if(!${this.requireFn}.o(exports, name)) {`,
|
237
|
+
Template.indent([
|
238
|
+
"Object.defineProperty(exports, name, {",
|
239
|
+
Template.indent([
|
240
|
+
"configurable: false,",
|
241
|
+
"enumerable: true,",
|
242
|
+
"get: getter"
|
243
|
+
]),
|
244
|
+
"});"
|
245
|
+
]),
|
246
|
+
"}"
|
247
|
+
])
|
248
|
+
);
|
249
|
+
buf.push("};");
|
250
|
+
|
251
|
+
buf.push("");
|
252
|
+
buf.push("// define __esModule on exports");
|
253
|
+
buf.push(`${this.requireFn}.r = function(exports) {`);
|
254
|
+
buf.push(
|
255
|
+
Template.indent([
|
256
|
+
"Object.defineProperty(exports, '__esModule', { value: true });"
|
257
|
+
])
|
258
|
+
);
|
259
|
+
buf.push("};");
|
260
|
+
|
261
|
+
buf.push("");
|
262
|
+
buf.push(
|
263
|
+
"// getDefaultExport function for compatibility with non-harmony modules"
|
264
|
+
);
|
265
|
+
buf.push(this.requireFn + ".n = function(module) {");
|
266
|
+
buf.push(
|
267
|
+
Template.indent([
|
268
|
+
"var getter = module && module.__esModule ?",
|
269
|
+
Template.indent([
|
270
|
+
"function getDefault() { return module['default']; } :",
|
271
|
+
"function getModuleExports() { return module; };"
|
272
|
+
]),
|
273
|
+
`${this.requireFn}.d(getter, 'a', getter);`,
|
274
|
+
"return getter;"
|
275
|
+
])
|
276
|
+
);
|
277
|
+
buf.push("};");
|
278
|
+
|
279
|
+
buf.push("");
|
280
|
+
buf.push("// Object.prototype.hasOwnProperty.call");
|
281
|
+
buf.push(
|
282
|
+
`${
|
283
|
+
this.requireFn
|
284
|
+
}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
|
285
|
+
);
|
286
|
+
|
287
|
+
const publicPath = this.getPublicPath({
|
288
|
+
hash: hash
|
289
|
+
});
|
290
|
+
buf.push("");
|
291
|
+
buf.push("// __webpack_public_path__");
|
292
|
+
buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
|
293
|
+
return Template.asString(buf);
|
294
|
+
});
|
295
|
+
|
296
|
+
this.requireFn = "__webpack_require__";
|
297
|
+
}
|
298
|
+
|
299
|
+
getRenderManifest(options) {
|
300
|
+
const result = [];
|
301
|
+
|
302
|
+
this.hooks.renderManifest.call(result, options);
|
303
|
+
|
304
|
+
return result;
|
305
|
+
}
|
306
|
+
|
307
|
+
render(hash, chunk, moduleTemplate, dependencyTemplates) {
|
308
|
+
const buf = [];
|
309
|
+
buf.push(
|
310
|
+
this.hooks.bootstrap.call(
|
311
|
+
"",
|
312
|
+
chunk,
|
313
|
+
hash,
|
314
|
+
moduleTemplate,
|
315
|
+
dependencyTemplates
|
316
|
+
)
|
317
|
+
);
|
318
|
+
buf.push(this.hooks.localVars.call("", chunk, hash));
|
319
|
+
buf.push("");
|
320
|
+
buf.push("// The require function");
|
321
|
+
buf.push(`function ${this.requireFn}(moduleId) {`);
|
322
|
+
buf.push(Template.indent(this.hooks.require.call("", chunk, hash)));
|
323
|
+
buf.push("}");
|
324
|
+
buf.push("");
|
325
|
+
buf.push(
|
326
|
+
Template.asString(this.hooks.requireExtensions.call("", chunk, hash))
|
327
|
+
);
|
328
|
+
buf.push("");
|
329
|
+
buf.push(Template.asString(this.hooks.beforeStartup.call("", chunk, hash)));
|
330
|
+
buf.push(Template.asString(this.hooks.startup.call("", chunk, hash)));
|
331
|
+
let source = this.hooks.render.call(
|
332
|
+
new OriginalSource(
|
333
|
+
Template.prefix(buf, " \t") + "\n",
|
334
|
+
"webpack/bootstrap"
|
335
|
+
),
|
336
|
+
chunk,
|
337
|
+
hash,
|
338
|
+
moduleTemplate,
|
339
|
+
dependencyTemplates
|
340
|
+
);
|
341
|
+
if (chunk.hasEntryModule()) {
|
342
|
+
source = this.hooks.renderWithEntry.call(source, chunk, hash);
|
343
|
+
}
|
344
|
+
if (!source)
|
345
|
+
throw new Error(
|
346
|
+
"Compiler error: MainTemplate plugin 'render' should return something"
|
347
|
+
);
|
348
|
+
chunk.rendered = true;
|
349
|
+
return new ConcatSource(source, ";");
|
350
|
+
}
|
351
|
+
|
352
|
+
renderRequireFunctionForModule(hash, chunk, varModuleId) {
|
353
|
+
return this.hooks.moduleRequire.call(
|
354
|
+
this.requireFn,
|
355
|
+
chunk,
|
356
|
+
hash,
|
357
|
+
varModuleId
|
358
|
+
);
|
359
|
+
}
|
360
|
+
|
361
|
+
renderAddModule(hash, chunk, varModuleId, varModule) {
|
362
|
+
return this.hooks.addModule.call(
|
363
|
+
`modules[${varModuleId}] = ${varModule};`,
|
364
|
+
chunk,
|
365
|
+
hash,
|
366
|
+
varModuleId,
|
367
|
+
varModule
|
368
|
+
);
|
369
|
+
}
|
370
|
+
|
371
|
+
renderCurrentHashCode(hash, length) {
|
372
|
+
length = length || Infinity;
|
373
|
+
return this.hooks.currentHash.call(
|
374
|
+
JSON.stringify(hash.substr(0, length)),
|
375
|
+
length
|
376
|
+
);
|
377
|
+
}
|
378
|
+
|
379
|
+
getPublicPath(options) {
|
380
|
+
return this.hooks.assetPath.call(
|
381
|
+
this.outputOptions.publicPath || "",
|
382
|
+
options
|
383
|
+
);
|
384
|
+
}
|
385
|
+
|
386
|
+
getAssetPath(path, options) {
|
387
|
+
return this.hooks.assetPath.call(path, options);
|
388
|
+
}
|
389
|
+
|
390
|
+
updateHash(hash) {
|
391
|
+
hash.update("maintemplate");
|
392
|
+
hash.update("3");
|
393
|
+
hash.update(this.outputOptions.publicPath + "");
|
394
|
+
this.hooks.hash.call(hash);
|
395
|
+
}
|
396
|
+
|
397
|
+
updateHashForChunk(hash, chunk) {
|
398
|
+
this.updateHash(hash);
|
399
|
+
this.hooks.hashForChunk.call(hash, chunk);
|
400
|
+
}
|
401
|
+
|
402
|
+
useChunkHash(chunk) {
|
403
|
+
const paths = this.hooks.globalHashPaths.call([]);
|
404
|
+
return !this.hooks.globalHash.call(chunk, paths);
|
405
|
+
}
|
406
|
+
};
|