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/ContextModule.js
CHANGED
@@ -1,685 +1,696 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
const path = require("path");
|
7
|
-
const util = require("util");
|
8
|
-
const
|
9
|
-
const
|
10
|
-
const
|
11
|
-
const
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
// type
|
16
|
-
//
|
17
|
-
//
|
18
|
-
|
19
|
-
|
20
|
-
let
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
this.
|
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
|
-
if (this.options.
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
if (this.options.
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
if (this.options.
|
108
|
-
|
109
|
-
if (this.options.
|
110
|
-
identifier +=
|
111
|
-
if (this.options.
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
if (
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
dep
|
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
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
if (
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
${this.
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
}
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
}
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
}
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
return
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
e
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
});
|
386
|
-
}
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
});
|
423
|
-
}
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
var
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
}
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
var
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
}
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
module.exports =
|
544
|
-
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
}
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
if (
|
590
|
-
return this.
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
}
|
599
|
-
if (
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
return this.
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
);
|
627
|
-
}
|
628
|
-
|
629
|
-
|
630
|
-
//
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
return this.
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
}
|
639
|
-
}
|
640
|
-
|
641
|
-
// TODO remove in webpack 5
|
642
|
-
Object.defineProperty(ContextModule.prototype, "
|
643
|
-
configurable: false,
|
644
|
-
get: util.deprecate(function() {
|
645
|
-
return this.options.
|
646
|
-
}, "ContextModule.
|
647
|
-
set: util.deprecate(function(value) {
|
648
|
-
this.options.
|
649
|
-
}, "ContextModule.
|
650
|
-
});
|
651
|
-
|
652
|
-
// TODO remove in webpack 5
|
653
|
-
Object.defineProperty(ContextModule.prototype, "
|
654
|
-
configurable: false,
|
655
|
-
get: util.deprecate(function() {
|
656
|
-
return this.options.
|
657
|
-
}, "ContextModule.
|
658
|
-
set: util.deprecate(function(value) {
|
659
|
-
this.options.
|
660
|
-
}, "ContextModule.
|
661
|
-
});
|
662
|
-
|
663
|
-
// TODO remove in webpack 5
|
664
|
-
Object.defineProperty(ContextModule.prototype, "
|
665
|
-
configurable: false,
|
666
|
-
get: util.deprecate(function() {
|
667
|
-
return this.options.
|
668
|
-
}, "ContextModule.
|
669
|
-
set: util.deprecate(function(value) {
|
670
|
-
this.options.
|
671
|
-
}, "ContextModule.
|
672
|
-
});
|
673
|
-
|
674
|
-
// TODO remove in webpack 5
|
675
|
-
Object.defineProperty(ContextModule.prototype, "
|
676
|
-
configurable: false,
|
677
|
-
get: util.deprecate(function() {
|
678
|
-
return this.options.
|
679
|
-
}, "ContextModule.
|
680
|
-
set: util.deprecate(function(value) {
|
681
|
-
this.options.
|
682
|
-
}, "ContextModule.
|
683
|
-
});
|
684
|
-
|
685
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
const path = require("path");
|
7
|
+
const util = require("util");
|
8
|
+
const { OriginalSource, RawSource } = require("webpack-sources");
|
9
|
+
const Module = require("./Module");
|
10
|
+
const AsyncDependenciesBlock = require("./AsyncDependenciesBlock");
|
11
|
+
const Template = require("./Template");
|
12
|
+
|
13
|
+
class ContextModule extends Module {
|
14
|
+
// type ContextMode = "sync" | "eager" | "weak" | "async-weak" | "lazy" | "lazy-once"
|
15
|
+
// type ContextOptions = { resource: string, recursive: boolean, regExp: RegExp, addon?: string, mode?: ContextMode, chunkName?: string, include?: RegExp, exclude?: RegExp }
|
16
|
+
// resolveDependencies: (fs: FS, options: ContextOptions, (err: Error?, dependencies: Dependency[]) => void) => void
|
17
|
+
// options: ContextOptions
|
18
|
+
constructor(resolveDependencies, options) {
|
19
|
+
let resource;
|
20
|
+
let resourceQuery;
|
21
|
+
const queryIdx = options.resource.indexOf("?");
|
22
|
+
if (queryIdx >= 0) {
|
23
|
+
resource = options.resource.substr(0, queryIdx);
|
24
|
+
resourceQuery = options.resource.substr(queryIdx);
|
25
|
+
} else {
|
26
|
+
resource = options.resource;
|
27
|
+
resourceQuery = "";
|
28
|
+
}
|
29
|
+
|
30
|
+
super("javascript/dynamic", resource);
|
31
|
+
|
32
|
+
// Info from Factory
|
33
|
+
this.resolveDependencies = resolveDependencies;
|
34
|
+
this.options = Object.assign({}, options, {
|
35
|
+
resource: resource,
|
36
|
+
resourceQuery: resourceQuery
|
37
|
+
});
|
38
|
+
if (options.resolveOptions !== undefined)
|
39
|
+
this.resolveOptions = options.resolveOptions;
|
40
|
+
|
41
|
+
// Info from Build
|
42
|
+
this._contextDependencies = new Set([this.context]);
|
43
|
+
|
44
|
+
if (typeof options.mode !== "string")
|
45
|
+
throw new Error("options.mode is a required option");
|
46
|
+
|
47
|
+
this._identifier = this._createIdentifier();
|
48
|
+
}
|
49
|
+
|
50
|
+
updateCacheModule(module) {
|
51
|
+
this.resolveDependencies = module.resolveDependencies;
|
52
|
+
this.options = module.options;
|
53
|
+
this.resolveOptions = module.resolveOptions;
|
54
|
+
}
|
55
|
+
|
56
|
+
prettyRegExp(regexString) {
|
57
|
+
// remove the "/" at the front and the beginning
|
58
|
+
// "/foo/" -> "foo"
|
59
|
+
return regexString.substring(1, regexString.length - 1);
|
60
|
+
}
|
61
|
+
|
62
|
+
contextify(context, request) {
|
63
|
+
return request
|
64
|
+
.split("!")
|
65
|
+
.map(subrequest => {
|
66
|
+
let rp = path.relative(context, subrequest);
|
67
|
+
if (path.sep === "\\") rp = rp.replace(/\\/g, "/");
|
68
|
+
if (rp.indexOf("../") !== 0) rp = "./" + rp;
|
69
|
+
return rp;
|
70
|
+
})
|
71
|
+
.join("!");
|
72
|
+
}
|
73
|
+
|
74
|
+
_createIdentifier() {
|
75
|
+
let identifier = this.context;
|
76
|
+
if (this.options.resourceQuery)
|
77
|
+
identifier += ` ${this.options.resourceQuery}`;
|
78
|
+
if (this.options.mode) identifier += ` ${this.options.mode}`;
|
79
|
+
if (!this.options.recursive) identifier += " nonrecursive";
|
80
|
+
if (this.options.addon) identifier += ` ${this.options.addon}`;
|
81
|
+
if (this.options.regExp) identifier += ` ${this.options.regExp}`;
|
82
|
+
if (this.options.include) identifier += ` include: ${this.options.include}`;
|
83
|
+
if (this.options.exclude) identifier += ` exclude: ${this.options.exclude}`;
|
84
|
+
if (this.options.namespaceObject === "strict")
|
85
|
+
identifier += " strict namespace object";
|
86
|
+
else if (this.options.namespaceObject) identifier += " namespace object";
|
87
|
+
|
88
|
+
return identifier;
|
89
|
+
}
|
90
|
+
|
91
|
+
identifier() {
|
92
|
+
return this._identifier;
|
93
|
+
}
|
94
|
+
|
95
|
+
readableIdentifier(requestShortener) {
|
96
|
+
let identifier = requestShortener.shorten(this.context);
|
97
|
+
if (this.options.resourceQuery)
|
98
|
+
identifier += ` ${this.options.resourceQuery}`;
|
99
|
+
if (this.options.mode) identifier += ` ${this.options.mode}`;
|
100
|
+
if (!this.options.recursive) identifier += " nonrecursive";
|
101
|
+
if (this.options.addon)
|
102
|
+
identifier += ` ${requestShortener.shorten(this.options.addon)}`;
|
103
|
+
if (this.options.regExp)
|
104
|
+
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
105
|
+
if (this.options.include)
|
106
|
+
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
107
|
+
if (this.options.exclude)
|
108
|
+
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
109
|
+
if (this.options.namespaceObject === "strict")
|
110
|
+
identifier += " strict namespace object";
|
111
|
+
else if (this.options.namespaceObject) identifier += " namespace object";
|
112
|
+
|
113
|
+
return identifier;
|
114
|
+
}
|
115
|
+
|
116
|
+
libIdent(options) {
|
117
|
+
let identifier = this.contextify(options.context, this.context);
|
118
|
+
if (this.options.mode) identifier += ` ${this.options.mode}`;
|
119
|
+
if (this.options.recursive) identifier += " recursive";
|
120
|
+
if (this.options.addon)
|
121
|
+
identifier += ` ${this.contextify(options.context, this.options.addon)}`;
|
122
|
+
if (this.options.regExp)
|
123
|
+
identifier += ` ${this.prettyRegExp(this.options.regExp + "")}`;
|
124
|
+
if (this.options.include)
|
125
|
+
identifier += ` include: ${this.prettyRegExp(this.options.include + "")}`;
|
126
|
+
if (this.options.exclude)
|
127
|
+
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude + "")}`;
|
128
|
+
|
129
|
+
return identifier;
|
130
|
+
}
|
131
|
+
|
132
|
+
needRebuild(fileTimestamps, contextTimestamps) {
|
133
|
+
const ts = contextTimestamps.get(this.context);
|
134
|
+
if (!ts) {
|
135
|
+
return true;
|
136
|
+
}
|
137
|
+
|
138
|
+
return ts >= this.buildInfo.builtTime;
|
139
|
+
}
|
140
|
+
|
141
|
+
build(options, compilation, resolver, fs, callback) {
|
142
|
+
this.built = true;
|
143
|
+
this.buildMeta = {};
|
144
|
+
this.buildInfo = {
|
145
|
+
builtTime: Date.now(),
|
146
|
+
contextDependencies: this._contextDependencies
|
147
|
+
};
|
148
|
+
this.resolveDependencies(fs, this.options, (err, dependencies) => {
|
149
|
+
if (err) return callback(err);
|
150
|
+
|
151
|
+
// abort if something failed
|
152
|
+
// this will create an empty context
|
153
|
+
if (!dependencies) {
|
154
|
+
callback();
|
155
|
+
return;
|
156
|
+
}
|
157
|
+
|
158
|
+
// enhance dependencies with meta info
|
159
|
+
for (const dep of dependencies) {
|
160
|
+
dep.loc = dep.userRequest;
|
161
|
+
dep.request = this.options.addon + dep.request;
|
162
|
+
}
|
163
|
+
|
164
|
+
if (this.options.mode === "sync" || this.options.mode === "eager") {
|
165
|
+
// if we have an sync or eager context
|
166
|
+
// just add all dependencies and continue
|
167
|
+
this.dependencies = dependencies;
|
168
|
+
} else if (this.options.mode === "lazy-once") {
|
169
|
+
// for the lazy-once mode create a new async dependency block
|
170
|
+
// and add that block to this context
|
171
|
+
if (dependencies.length > 0) {
|
172
|
+
const block = new AsyncDependenciesBlock(
|
173
|
+
this.options.chunkName,
|
174
|
+
this
|
175
|
+
);
|
176
|
+
for (const dep of dependencies) {
|
177
|
+
block.addDependency(dep);
|
178
|
+
}
|
179
|
+
this.addBlock(block);
|
180
|
+
}
|
181
|
+
} else if (
|
182
|
+
this.options.mode === "weak" ||
|
183
|
+
this.options.mode === "async-weak"
|
184
|
+
) {
|
185
|
+
// we mark all dependencies as weak
|
186
|
+
for (const dep of dependencies) {
|
187
|
+
dep.weak = true;
|
188
|
+
}
|
189
|
+
this.dependencies = dependencies;
|
190
|
+
} else if (this.options.mode === "lazy") {
|
191
|
+
// if we are lazy create a new async dependency block per dependency
|
192
|
+
// and add all blocks to this context
|
193
|
+
let index = 0;
|
194
|
+
for (const dep of dependencies) {
|
195
|
+
let chunkName = this.options.chunkName;
|
196
|
+
if (chunkName) {
|
197
|
+
if (!/\[(index|request)\]/.test(chunkName)) chunkName += "[index]";
|
198
|
+
chunkName = chunkName.replace(/\[index\]/g, index++);
|
199
|
+
chunkName = chunkName.replace(
|
200
|
+
/\[request\]/g,
|
201
|
+
Template.toPath(dep.userRequest)
|
202
|
+
);
|
203
|
+
}
|
204
|
+
const block = new AsyncDependenciesBlock(
|
205
|
+
chunkName,
|
206
|
+
dep.module,
|
207
|
+
dep.loc,
|
208
|
+
dep.userRequest
|
209
|
+
);
|
210
|
+
block.addDependency(dep);
|
211
|
+
this.addBlock(block);
|
212
|
+
}
|
213
|
+
} else {
|
214
|
+
callback(
|
215
|
+
new Error(`Unsupported mode "${this.options.mode}" in context`)
|
216
|
+
);
|
217
|
+
return;
|
218
|
+
}
|
219
|
+
callback();
|
220
|
+
});
|
221
|
+
}
|
222
|
+
|
223
|
+
getUserRequestMap(dependencies) {
|
224
|
+
// if we filter first we get a new array
|
225
|
+
// therefor we dont need to create a clone of dependencies explicitly
|
226
|
+
// therefore the order of this is !important!
|
227
|
+
return dependencies
|
228
|
+
.filter(dependency => dependency.module)
|
229
|
+
.sort((a, b) => {
|
230
|
+
if (a.userRequest === b.userRequest) {
|
231
|
+
return 0;
|
232
|
+
}
|
233
|
+
return a.userRequest < b.userRequest ? -1 : 1;
|
234
|
+
})
|
235
|
+
.reduce((map, dep) => {
|
236
|
+
map[dep.userRequest] = dep.module.id;
|
237
|
+
return map;
|
238
|
+
}, Object.create(null));
|
239
|
+
}
|
240
|
+
|
241
|
+
getFakeMap(dependencies) {
|
242
|
+
if (!this.options.namespaceObject) return 1;
|
243
|
+
// if we filter first we get a new array
|
244
|
+
// therefor we dont need to create a clone of dependencies explicitly
|
245
|
+
// therefore the order of this is !important!
|
246
|
+
let hasNonHarmony = false;
|
247
|
+
let hasNamespace = false;
|
248
|
+
let hasNamed = false;
|
249
|
+
const fakeMap = dependencies
|
250
|
+
.filter(dependency => dependency.module)
|
251
|
+
.sort((a, b) => {
|
252
|
+
return b.module.id - a.module.id;
|
253
|
+
})
|
254
|
+
.reduce((map, dep) => {
|
255
|
+
const exportsType =
|
256
|
+
dep.module.buildMeta && dep.module.buildMeta.exportsType;
|
257
|
+
if (!exportsType) hasNonHarmony = true;
|
258
|
+
if (exportsType === "namespace") hasNamespace = true;
|
259
|
+
if (exportsType === "named") hasNamed = true;
|
260
|
+
map[dep.module.id] =
|
261
|
+
{
|
262
|
+
namespace: 1,
|
263
|
+
named: 2
|
264
|
+
}[exportsType] || 0;
|
265
|
+
return map;
|
266
|
+
}, Object.create(null));
|
267
|
+
if (!hasNamespace && hasNonHarmony && !hasNamed) return 0;
|
268
|
+
if (hasNamespace && !hasNonHarmony && !hasNamed) return 1;
|
269
|
+
if (!hasNamespace && !hasNonHarmony && hasNamed) return 2;
|
270
|
+
if (!hasNamespace && !hasNonHarmony && !hasNamed) return 1;
|
271
|
+
return fakeMap;
|
272
|
+
}
|
273
|
+
|
274
|
+
getFakeMapInitStatement(fakeMap) {
|
275
|
+
return typeof fakeMap === "object"
|
276
|
+
? `var fakeMap = ${JSON.stringify(fakeMap, null, "\t")};`
|
277
|
+
: "";
|
278
|
+
}
|
279
|
+
|
280
|
+
getReturn(type) {
|
281
|
+
if (type === 1) return "module";
|
282
|
+
if (type === 2)
|
283
|
+
return 'Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module })';
|
284
|
+
if (type === 0) {
|
285
|
+
if (this.options.namespaceObject === "strict") {
|
286
|
+
return '/* fake namespace object */ { "default": module }';
|
287
|
+
} else {
|
288
|
+
return '(typeof module === "object" && module && module.__esModule ? module : Object.assign({/* fake namespace object */}, typeof module === "object" && module, { "default": module }))';
|
289
|
+
}
|
290
|
+
}
|
291
|
+
}
|
292
|
+
|
293
|
+
getReturnModuleObjectSource(fakeMap, fakeMapDataExpression = "fakeMap[id]") {
|
294
|
+
if (typeof fakeMap === "number")
|
295
|
+
return `return ${this.getReturn(fakeMap)};`;
|
296
|
+
return `return ${fakeMapDataExpression} === 1 ? ${this.getReturn(
|
297
|
+
1
|
298
|
+
)} : ${fakeMapDataExpression} ? ${this.getReturn(2)} : ${this.getReturn(
|
299
|
+
0
|
300
|
+
)};`;
|
301
|
+
}
|
302
|
+
|
303
|
+
getSyncSource(dependencies, id) {
|
304
|
+
const map = this.getUserRequestMap(dependencies);
|
305
|
+
const fakeMap = this.getFakeMap(dependencies);
|
306
|
+
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
307
|
+
|
308
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
309
|
+
${this.getFakeMapInitStatement(fakeMap)}
|
310
|
+
|
311
|
+
function webpackContext(req) {
|
312
|
+
var id = webpackContextResolve(req);
|
313
|
+
var module = __webpack_require__(id);
|
314
|
+
${returnModuleObject}
|
315
|
+
}
|
316
|
+
function webpackContextResolve(req) {
|
317
|
+
var id = map[req];
|
318
|
+
if(!(id + 1)) { // check for number or string
|
319
|
+
var e = new Error('Cannot find module "' + req + '".');
|
320
|
+
e.code = 'MODULE_NOT_FOUND';
|
321
|
+
throw e;
|
322
|
+
}
|
323
|
+
return id;
|
324
|
+
}
|
325
|
+
webpackContext.keys = function webpackContextKeys() {
|
326
|
+
return Object.keys(map);
|
327
|
+
};
|
328
|
+
webpackContext.resolve = webpackContextResolve;
|
329
|
+
module.exports = webpackContext;
|
330
|
+
webpackContext.id = ${JSON.stringify(id)};`;
|
331
|
+
}
|
332
|
+
|
333
|
+
getWeakSyncSource(dependencies, id) {
|
334
|
+
const map = this.getUserRequestMap(dependencies);
|
335
|
+
const fakeMap = this.getFakeMap(dependencies);
|
336
|
+
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
337
|
+
|
338
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
339
|
+
${this.getFakeMapInitStatement(fakeMap)}
|
340
|
+
|
341
|
+
function webpackContext(req) {
|
342
|
+
var id = webpackContextResolve(req);
|
343
|
+
if(!__webpack_require__.m[id]) {
|
344
|
+
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
|
345
|
+
e.code = 'MODULE_NOT_FOUND';
|
346
|
+
throw e;
|
347
|
+
}
|
348
|
+
var module = __webpack_require__(id);
|
349
|
+
${returnModuleObject}
|
350
|
+
}
|
351
|
+
function webpackContextResolve(req) {
|
352
|
+
var id = map[req];
|
353
|
+
if(!(id + 1)) { // check for number or string
|
354
|
+
var e = new Error('Cannot find module "' + req + '".');
|
355
|
+
e.code = 'MODULE_NOT_FOUND';
|
356
|
+
throw e;
|
357
|
+
}
|
358
|
+
return id;
|
359
|
+
}
|
360
|
+
webpackContext.keys = function webpackContextKeys() {
|
361
|
+
return Object.keys(map);
|
362
|
+
};
|
363
|
+
webpackContext.resolve = webpackContextResolve;
|
364
|
+
webpackContext.id = ${JSON.stringify(id)};
|
365
|
+
module.exports = webpackContext;`;
|
366
|
+
}
|
367
|
+
|
368
|
+
getAsyncWeakSource(dependencies, id) {
|
369
|
+
const map = this.getUserRequestMap(dependencies);
|
370
|
+
const fakeMap = this.getFakeMap(dependencies);
|
371
|
+
const returnModuleObject = this.getReturnModuleObjectSource(fakeMap);
|
372
|
+
|
373
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
374
|
+
${this.getFakeMapInitStatement(fakeMap)}
|
375
|
+
|
376
|
+
function webpackAsyncContext(req) {
|
377
|
+
return webpackAsyncContextResolve(req).then(function(id) {
|
378
|
+
if(!__webpack_require__.m[id]) {
|
379
|
+
var e = new Error("Module '" + req + "' ('" + id + "') is not available (weak dependency)");
|
380
|
+
e.code = 'MODULE_NOT_FOUND';
|
381
|
+
throw e;
|
382
|
+
}
|
383
|
+
var module = __webpack_require__(id);
|
384
|
+
${returnModuleObject}
|
385
|
+
});
|
386
|
+
}
|
387
|
+
function webpackAsyncContextResolve(req) {
|
388
|
+
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
389
|
+
// uncaught exception popping up in devtools
|
390
|
+
return Promise.resolve().then(function() {
|
391
|
+
var id = map[req];
|
392
|
+
if(!(id + 1)) { // check for number or string
|
393
|
+
var e = new Error('Cannot find module "' + req + '".');
|
394
|
+
e.code = 'MODULE_NOT_FOUND';
|
395
|
+
throw e;
|
396
|
+
}
|
397
|
+
return id;
|
398
|
+
});
|
399
|
+
}
|
400
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
401
|
+
return Object.keys(map);
|
402
|
+
};
|
403
|
+
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
404
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};
|
405
|
+
module.exports = webpackAsyncContext;`;
|
406
|
+
}
|
407
|
+
|
408
|
+
getEagerSource(dependencies, id) {
|
409
|
+
const map = this.getUserRequestMap(dependencies);
|
410
|
+
const fakeMap = this.getFakeMap(dependencies);
|
411
|
+
const thenFunction =
|
412
|
+
fakeMap !== 1
|
413
|
+
? `function(id) {
|
414
|
+
var module = __webpack_require__(id);
|
415
|
+
${this.getReturnModuleObjectSource(fakeMap)}
|
416
|
+
}`
|
417
|
+
: "__webpack_require__";
|
418
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
419
|
+
${this.getFakeMapInitStatement(fakeMap)}
|
420
|
+
|
421
|
+
function webpackAsyncContext(req) {
|
422
|
+
return webpackAsyncContextResolve(req).then(${thenFunction});
|
423
|
+
}
|
424
|
+
function webpackAsyncContextResolve(req) {
|
425
|
+
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
426
|
+
// uncaught exception popping up in devtools
|
427
|
+
return Promise.resolve().then(function() {
|
428
|
+
var id = map[req];
|
429
|
+
if(!(id + 1)) { // check for number or string
|
430
|
+
var e = new Error('Cannot find module "' + req + '".');
|
431
|
+
e.code = 'MODULE_NOT_FOUND';
|
432
|
+
throw e;
|
433
|
+
}
|
434
|
+
return id;
|
435
|
+
});
|
436
|
+
}
|
437
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
438
|
+
return Object.keys(map);
|
439
|
+
};
|
440
|
+
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
441
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};
|
442
|
+
module.exports = webpackAsyncContext;`;
|
443
|
+
}
|
444
|
+
|
445
|
+
getLazyOnceSource(block, dependencies, id, runtimeTemplate) {
|
446
|
+
const promise = runtimeTemplate.blockPromise({
|
447
|
+
block,
|
448
|
+
message: "lazy-once context"
|
449
|
+
});
|
450
|
+
const map = this.getUserRequestMap(dependencies);
|
451
|
+
const fakeMap = this.getFakeMap(dependencies);
|
452
|
+
const thenFunction =
|
453
|
+
fakeMap !== 1
|
454
|
+
? `function(id) {
|
455
|
+
var module = __webpack_require__(id);
|
456
|
+
${this.getReturnModuleObjectSource(fakeMap)};
|
457
|
+
}`
|
458
|
+
: "__webpack_require__";
|
459
|
+
|
460
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
461
|
+
${this.getFakeMapInitStatement(fakeMap)}
|
462
|
+
|
463
|
+
function webpackAsyncContext(req) {
|
464
|
+
return webpackAsyncContextResolve(req).then(${thenFunction});
|
465
|
+
}
|
466
|
+
function webpackAsyncContextResolve(req) {
|
467
|
+
return ${promise}.then(function() {
|
468
|
+
var id = map[req];
|
469
|
+
if(!(id + 1)) { // check for number or string
|
470
|
+
var e = new Error('Cannot find module "' + req + '".');
|
471
|
+
e.code = 'MODULE_NOT_FOUND';
|
472
|
+
throw e;
|
473
|
+
}
|
474
|
+
return id;
|
475
|
+
});
|
476
|
+
}
|
477
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
478
|
+
return Object.keys(map);
|
479
|
+
};
|
480
|
+
webpackAsyncContext.resolve = webpackAsyncContextResolve;
|
481
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};
|
482
|
+
module.exports = webpackAsyncContext;`;
|
483
|
+
}
|
484
|
+
|
485
|
+
getLazySource(blocks, id) {
|
486
|
+
let hasMultipleOrNoChunks = false;
|
487
|
+
const fakeMap = this.getFakeMap(blocks.map(b => b.dependencies[0]));
|
488
|
+
const map = blocks
|
489
|
+
.filter(block => block.dependencies[0].module)
|
490
|
+
.map(block => ({
|
491
|
+
dependency: block.dependencies[0],
|
492
|
+
block: block,
|
493
|
+
userRequest: block.dependencies[0].userRequest
|
494
|
+
}))
|
495
|
+
.sort((a, b) => {
|
496
|
+
if (a.userRequest === b.userRequest) return 0;
|
497
|
+
return a.userRequest < b.userRequest ? -1 : 1;
|
498
|
+
})
|
499
|
+
.reduce((map, item) => {
|
500
|
+
const chunks =
|
501
|
+
(item.block.chunkGroup && item.block.chunkGroup.chunks) || [];
|
502
|
+
if (chunks.length !== 1) {
|
503
|
+
hasMultipleOrNoChunks = true;
|
504
|
+
}
|
505
|
+
const arrayStart = [item.dependency.module.id];
|
506
|
+
if (typeof fakeMap === "object")
|
507
|
+
arrayStart.push(fakeMap[item.dependency.module.id]);
|
508
|
+
map[item.userRequest] = arrayStart.concat(
|
509
|
+
chunks.map(chunk => chunk.id)
|
510
|
+
);
|
511
|
+
|
512
|
+
return map;
|
513
|
+
}, Object.create(null));
|
514
|
+
|
515
|
+
const chunksStartPosition = typeof fakeMap === "object" ? 2 : 1;
|
516
|
+
const requestPrefix = hasMultipleOrNoChunks
|
517
|
+
? `Promise.all(ids.slice(${chunksStartPosition}).map(__webpack_require__.e))`
|
518
|
+
: `__webpack_require__.e(ids[${chunksStartPosition}])`;
|
519
|
+
const returnModuleObject = this.getReturnModuleObjectSource(
|
520
|
+
fakeMap,
|
521
|
+
"ids[1]"
|
522
|
+
);
|
523
|
+
|
524
|
+
return `var map = ${JSON.stringify(map, null, "\t")};
|
525
|
+
function webpackAsyncContext(req) {
|
526
|
+
var ids = map[req];
|
527
|
+
if(!ids) {
|
528
|
+
return Promise.resolve().then(function() {
|
529
|
+
var e = new Error('Cannot find module "' + req + '".');
|
530
|
+
e.code = 'MODULE_NOT_FOUND';
|
531
|
+
throw e;
|
532
|
+
});
|
533
|
+
}
|
534
|
+
return ${requestPrefix}.then(function() {
|
535
|
+
var module = __webpack_require__(ids[0]);
|
536
|
+
${returnModuleObject}
|
537
|
+
});
|
538
|
+
}
|
539
|
+
webpackAsyncContext.keys = function webpackAsyncContextKeys() {
|
540
|
+
return Object.keys(map);
|
541
|
+
};
|
542
|
+
webpackAsyncContext.id = ${JSON.stringify(id)};
|
543
|
+
module.exports = webpackAsyncContext;`;
|
544
|
+
}
|
545
|
+
|
546
|
+
getSourceForEmptyContext(id) {
|
547
|
+
return `function webpackEmptyContext(req) {
|
548
|
+
var e = new Error('Cannot find module "' + req + '".');
|
549
|
+
e.code = 'MODULE_NOT_FOUND';
|
550
|
+
throw e;
|
551
|
+
}
|
552
|
+
webpackEmptyContext.keys = function() { return []; };
|
553
|
+
webpackEmptyContext.resolve = webpackEmptyContext;
|
554
|
+
module.exports = webpackEmptyContext;
|
555
|
+
webpackEmptyContext.id = ${JSON.stringify(id)};`;
|
556
|
+
}
|
557
|
+
|
558
|
+
getSourceForEmptyAsyncContext(id) {
|
559
|
+
return `function webpackEmptyAsyncContext(req) {
|
560
|
+
// Here Promise.resolve().then() is used instead of new Promise() to prevent
|
561
|
+
// uncaught exception popping up in devtools
|
562
|
+
return Promise.resolve().then(function() {
|
563
|
+
var e = new Error('Cannot find module "' + req + '".');
|
564
|
+
e.code = 'MODULE_NOT_FOUND';
|
565
|
+
throw e;
|
566
|
+
});
|
567
|
+
}
|
568
|
+
webpackEmptyAsyncContext.keys = function() { return []; };
|
569
|
+
webpackEmptyAsyncContext.resolve = webpackEmptyAsyncContext;
|
570
|
+
module.exports = webpackEmptyAsyncContext;
|
571
|
+
webpackEmptyAsyncContext.id = ${JSON.stringify(id)};`;
|
572
|
+
}
|
573
|
+
|
574
|
+
getSourceString(asyncMode, runtimeTemplate) {
|
575
|
+
if (asyncMode === "lazy") {
|
576
|
+
if (this.blocks && this.blocks.length > 0) {
|
577
|
+
return this.getLazySource(this.blocks, this.id);
|
578
|
+
}
|
579
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
580
|
+
}
|
581
|
+
if (asyncMode === "eager") {
|
582
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
583
|
+
return this.getEagerSource(this.dependencies, this.id);
|
584
|
+
}
|
585
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
586
|
+
}
|
587
|
+
if (asyncMode === "lazy-once") {
|
588
|
+
const block = this.blocks[0];
|
589
|
+
if (block) {
|
590
|
+
return this.getLazyOnceSource(
|
591
|
+
block,
|
592
|
+
block.dependencies,
|
593
|
+
this.id,
|
594
|
+
runtimeTemplate
|
595
|
+
);
|
596
|
+
}
|
597
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
598
|
+
}
|
599
|
+
if (asyncMode === "async-weak") {
|
600
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
601
|
+
return this.getAsyncWeakSource(this.dependencies, this.id);
|
602
|
+
}
|
603
|
+
return this.getSourceForEmptyAsyncContext(this.id);
|
604
|
+
}
|
605
|
+
if (asyncMode === "weak") {
|
606
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
607
|
+
return this.getWeakSyncSource(this.dependencies, this.id);
|
608
|
+
}
|
609
|
+
}
|
610
|
+
if (this.dependencies && this.dependencies.length > 0) {
|
611
|
+
return this.getSyncSource(this.dependencies, this.id);
|
612
|
+
}
|
613
|
+
return this.getSourceForEmptyContext(this.id);
|
614
|
+
}
|
615
|
+
|
616
|
+
getSource(sourceString) {
|
617
|
+
if (this.useSourceMap) {
|
618
|
+
return new OriginalSource(sourceString, this.identifier());
|
619
|
+
}
|
620
|
+
return new RawSource(sourceString);
|
621
|
+
}
|
622
|
+
|
623
|
+
source(dependencyTemplates, runtimeTemplate) {
|
624
|
+
return this.getSource(
|
625
|
+
this.getSourceString(this.options.mode, runtimeTemplate)
|
626
|
+
);
|
627
|
+
}
|
628
|
+
|
629
|
+
size() {
|
630
|
+
// base penalty
|
631
|
+
const initialSize = 160;
|
632
|
+
|
633
|
+
// if we dont have dependencies we stop here.
|
634
|
+
return this.dependencies.reduce(
|
635
|
+
(size, dependency) => size + 5 + dependency.userRequest.length,
|
636
|
+
initialSize
|
637
|
+
);
|
638
|
+
}
|
639
|
+
}
|
640
|
+
|
641
|
+
// TODO remove in webpack 5
|
642
|
+
Object.defineProperty(ContextModule.prototype, "recursive", {
|
643
|
+
configurable: false,
|
644
|
+
get: util.deprecate(function() {
|
645
|
+
return this.options.recursive;
|
646
|
+
}, "ContextModule.recursive has been moved to ContextModule.options.recursive"),
|
647
|
+
set: util.deprecate(function(value) {
|
648
|
+
this.options.recursive = value;
|
649
|
+
}, "ContextModule.recursive has been moved to ContextModule.options.recursive")
|
650
|
+
});
|
651
|
+
|
652
|
+
// TODO remove in webpack 5
|
653
|
+
Object.defineProperty(ContextModule.prototype, "regExp", {
|
654
|
+
configurable: false,
|
655
|
+
get: util.deprecate(function() {
|
656
|
+
return this.options.regExp;
|
657
|
+
}, "ContextModule.regExp has been moved to ContextModule.options.regExp"),
|
658
|
+
set: util.deprecate(function(value) {
|
659
|
+
this.options.regExp = value;
|
660
|
+
}, "ContextModule.regExp has been moved to ContextModule.options.regExp")
|
661
|
+
});
|
662
|
+
|
663
|
+
// TODO remove in webpack 5
|
664
|
+
Object.defineProperty(ContextModule.prototype, "addon", {
|
665
|
+
configurable: false,
|
666
|
+
get: util.deprecate(function() {
|
667
|
+
return this.options.addon;
|
668
|
+
}, "ContextModule.addon has been moved to ContextModule.options.addon"),
|
669
|
+
set: util.deprecate(function(value) {
|
670
|
+
this.options.addon = value;
|
671
|
+
}, "ContextModule.addon has been moved to ContextModule.options.addon")
|
672
|
+
});
|
673
|
+
|
674
|
+
// TODO remove in webpack 5
|
675
|
+
Object.defineProperty(ContextModule.prototype, "async", {
|
676
|
+
configurable: false,
|
677
|
+
get: util.deprecate(function() {
|
678
|
+
return this.options.mode;
|
679
|
+
}, "ContextModule.async has been moved to ContextModule.options.mode"),
|
680
|
+
set: util.deprecate(function(value) {
|
681
|
+
this.options.mode = value;
|
682
|
+
}, "ContextModule.async has been moved to ContextModule.options.mode")
|
683
|
+
});
|
684
|
+
|
685
|
+
// TODO remove in webpack 5
|
686
|
+
Object.defineProperty(ContextModule.prototype, "chunkName", {
|
687
|
+
configurable: false,
|
688
|
+
get: util.deprecate(function() {
|
689
|
+
return this.options.chunkName;
|
690
|
+
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName"),
|
691
|
+
set: util.deprecate(function(value) {
|
692
|
+
this.options.chunkName = value;
|
693
|
+
}, "ContextModule.chunkName has been moved to ContextModule.options.chunkName")
|
694
|
+
});
|
695
|
+
|
696
|
+
module.exports = ContextModule;
|