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
@@ -1,403 +1,425 @@
|
|
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
|
-
const
|
9
|
-
|
10
|
-
class JsonpMainTemplatePlugin {
|
11
|
-
apply(mainTemplate) {
|
12
|
-
const needChunkOnDemandLoadingCode = chunk => {
|
13
|
-
for (const chunkGroup of chunk.groupsIterable) {
|
14
|
-
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
15
|
-
}
|
16
|
-
return false;
|
17
|
-
};
|
18
|
-
const needChunkLoadingCode = chunk => {
|
19
|
-
for (const chunkGroup of chunk.groupsIterable) {
|
20
|
-
if (chunkGroup.chunks.length > 1) return true;
|
21
|
-
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
22
|
-
}
|
23
|
-
return false;
|
24
|
-
};
|
25
|
-
const needEntryDeferringCode = chunk => {
|
26
|
-
for (const chunkGroup of chunk.groupsIterable) {
|
27
|
-
if (chunkGroup.chunks.length > 1) return true;
|
28
|
-
}
|
29
|
-
return false;
|
30
|
-
};
|
31
|
-
// TODO refactor this
|
32
|
-
if (!mainTemplate.hooks.jsonpScript) {
|
33
|
-
mainTemplate.hooks.jsonpScript = new SyncWaterfallHook([
|
34
|
-
"source",
|
35
|
-
"chunk",
|
36
|
-
"hash"
|
37
|
-
]);
|
38
|
-
}
|
39
|
-
|
40
|
-
mainTemplate.hooks.localVars.tap(
|
41
|
-
"JsonpMainTemplatePlugin",
|
42
|
-
(source, chunk) => {
|
43
|
-
if (needChunkLoadingCode(chunk)) {
|
44
|
-
return Template.asString([
|
45
|
-
source,
|
46
|
-
"",
|
47
|
-
"// object to store loaded and loading chunks",
|
48
|
-
"var installedChunks = {",
|
49
|
-
Template.indent(
|
50
|
-
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
|
51
|
-
),
|
52
|
-
"};",
|
53
|
-
"",
|
54
|
-
needEntryDeferringCode(chunk) ? "var deferredModules = [];" : ""
|
55
|
-
]);
|
56
|
-
}
|
57
|
-
return source;
|
58
|
-
}
|
59
|
-
);
|
60
|
-
mainTemplate.hooks.jsonpScript.tap(
|
61
|
-
"JsonpMainTemplatePlugin",
|
62
|
-
(_, chunk, hash) => {
|
63
|
-
const chunkFilename = mainTemplate.outputOptions.chunkFilename;
|
64
|
-
const chunkMaps = chunk.getChunkMaps();
|
65
|
-
const crossOriginLoading =
|
66
|
-
mainTemplate.outputOptions.crossOriginLoading;
|
67
|
-
const chunkLoadTimeout = mainTemplate.outputOptions.chunkLoadTimeout;
|
68
|
-
const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType;
|
69
|
-
const scriptSrcPath = mainTemplate.getAssetPath(
|
70
|
-
JSON.stringify(chunkFilename),
|
71
|
-
{
|
72
|
-
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
73
|
-
hashWithLength: length =>
|
74
|
-
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
75
|
-
chunk: {
|
76
|
-
id: '" + chunkId + "',
|
77
|
-
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
78
|
-
hashWithLength(length) {
|
79
|
-
const shortChunkHashMap = Object.create(null);
|
80
|
-
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
81
|
-
if (typeof chunkMaps.hash[chunkId] === "string")
|
82
|
-
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
83
|
-
0,
|
84
|
-
length
|
85
|
-
);
|
86
|
-
}
|
87
|
-
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
88
|
-
},
|
89
|
-
name: `" + (${JSON.stringify(
|
90
|
-
chunkMaps.name
|
91
|
-
)}[chunkId]||chunkId) + "
|
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
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
]);
|
305
|
-
}
|
306
|
-
return source;
|
307
|
-
}
|
308
|
-
);
|
309
|
-
mainTemplate.hooks.
|
310
|
-
"JsonpMainTemplatePlugin",
|
311
|
-
(source, chunk, hash) => {
|
312
|
-
if (
|
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
|
-
const
|
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
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const { SyncWaterfallHook } = require("tapable");
|
8
|
+
const Template = require("../Template");
|
9
|
+
|
10
|
+
class JsonpMainTemplatePlugin {
|
11
|
+
apply(mainTemplate) {
|
12
|
+
const needChunkOnDemandLoadingCode = chunk => {
|
13
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
14
|
+
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
15
|
+
}
|
16
|
+
return false;
|
17
|
+
};
|
18
|
+
const needChunkLoadingCode = chunk => {
|
19
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
20
|
+
if (chunkGroup.chunks.length > 1) return true;
|
21
|
+
if (chunkGroup.getNumberOfChildren() > 0) return true;
|
22
|
+
}
|
23
|
+
return false;
|
24
|
+
};
|
25
|
+
const needEntryDeferringCode = chunk => {
|
26
|
+
for (const chunkGroup of chunk.groupsIterable) {
|
27
|
+
if (chunkGroup.chunks.length > 1) return true;
|
28
|
+
}
|
29
|
+
return false;
|
30
|
+
};
|
31
|
+
// TODO refactor this
|
32
|
+
if (!mainTemplate.hooks.jsonpScript) {
|
33
|
+
mainTemplate.hooks.jsonpScript = new SyncWaterfallHook([
|
34
|
+
"source",
|
35
|
+
"chunk",
|
36
|
+
"hash"
|
37
|
+
]);
|
38
|
+
}
|
39
|
+
|
40
|
+
mainTemplate.hooks.localVars.tap(
|
41
|
+
"JsonpMainTemplatePlugin",
|
42
|
+
(source, chunk) => {
|
43
|
+
if (needChunkLoadingCode(chunk)) {
|
44
|
+
return Template.asString([
|
45
|
+
source,
|
46
|
+
"",
|
47
|
+
"// object to store loaded and loading chunks",
|
48
|
+
"var installedChunks = {",
|
49
|
+
Template.indent(
|
50
|
+
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
|
51
|
+
),
|
52
|
+
"};",
|
53
|
+
"",
|
54
|
+
needEntryDeferringCode(chunk) ? "var deferredModules = [];" : ""
|
55
|
+
]);
|
56
|
+
}
|
57
|
+
return source;
|
58
|
+
}
|
59
|
+
);
|
60
|
+
mainTemplate.hooks.jsonpScript.tap(
|
61
|
+
"JsonpMainTemplatePlugin",
|
62
|
+
(_, chunk, hash) => {
|
63
|
+
const chunkFilename = mainTemplate.outputOptions.chunkFilename;
|
64
|
+
const chunkMaps = chunk.getChunkMaps();
|
65
|
+
const crossOriginLoading =
|
66
|
+
mainTemplate.outputOptions.crossOriginLoading;
|
67
|
+
const chunkLoadTimeout = mainTemplate.outputOptions.chunkLoadTimeout;
|
68
|
+
const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType;
|
69
|
+
const scriptSrcPath = mainTemplate.getAssetPath(
|
70
|
+
JSON.stringify(chunkFilename),
|
71
|
+
{
|
72
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
73
|
+
hashWithLength: length =>
|
74
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
75
|
+
chunk: {
|
76
|
+
id: '" + chunkId + "',
|
77
|
+
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
78
|
+
hashWithLength(length) {
|
79
|
+
const shortChunkHashMap = Object.create(null);
|
80
|
+
for (const chunkId of Object.keys(chunkMaps.hash)) {
|
81
|
+
if (typeof chunkMaps.hash[chunkId] === "string")
|
82
|
+
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(
|
83
|
+
0,
|
84
|
+
length
|
85
|
+
);
|
86
|
+
}
|
87
|
+
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
88
|
+
},
|
89
|
+
name: `" + (${JSON.stringify(
|
90
|
+
chunkMaps.name
|
91
|
+
)}[chunkId]||chunkId) + "`,
|
92
|
+
contentHash: {
|
93
|
+
javascript: `" + ${JSON.stringify(
|
94
|
+
chunkMaps.contentHash.javascript
|
95
|
+
)}[chunkId] + "`
|
96
|
+
},
|
97
|
+
contentHashWithLength: {
|
98
|
+
javascript: length => {
|
99
|
+
const shortContentHashMap = {};
|
100
|
+
const contentHash = chunkMaps.contentHash.javascript;
|
101
|
+
for (const chunkId of Object.keys(contentHash)) {
|
102
|
+
if (typeof contentHash[chunkId] === "string") {
|
103
|
+
shortContentHashMap[chunkId] = contentHash[
|
104
|
+
chunkId
|
105
|
+
].substr(0, length);
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return `" + ${JSON.stringify(
|
109
|
+
shortContentHashMap
|
110
|
+
)}[chunkId] + "`;
|
111
|
+
}
|
112
|
+
}
|
113
|
+
},
|
114
|
+
contentHashType: "javascript"
|
115
|
+
}
|
116
|
+
);
|
117
|
+
return Template.asString([
|
118
|
+
"var script = document.createElement('script');",
|
119
|
+
jsonpScriptType
|
120
|
+
? `script.type = ${JSON.stringify(jsonpScriptType)};`
|
121
|
+
: "",
|
122
|
+
"script.charset = 'utf-8';",
|
123
|
+
`script.timeout = ${chunkLoadTimeout / 1000};`,
|
124
|
+
crossOriginLoading
|
125
|
+
? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
|
126
|
+
: "",
|
127
|
+
`if (${mainTemplate.requireFn}.nc) {`,
|
128
|
+
Template.indent(
|
129
|
+
`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`
|
130
|
+
),
|
131
|
+
"}",
|
132
|
+
`script.src = ${mainTemplate.requireFn}.p + ${scriptSrcPath};`,
|
133
|
+
"var timeout = setTimeout(function(){",
|
134
|
+
Template.indent([
|
135
|
+
"onScriptComplete({ type: 'timeout', target: script });"
|
136
|
+
]),
|
137
|
+
`}, ${chunkLoadTimeout});`,
|
138
|
+
"script.onerror = script.onload = onScriptComplete;",
|
139
|
+
"function onScriptComplete(event) {",
|
140
|
+
Template.indent([
|
141
|
+
"// avoid mem leaks in IE.",
|
142
|
+
"script.onerror = script.onload = null;",
|
143
|
+
"clearTimeout(timeout);",
|
144
|
+
"var chunk = installedChunks[chunkId];",
|
145
|
+
"if(chunk !== 0) {",
|
146
|
+
Template.indent([
|
147
|
+
"if(chunk) {",
|
148
|
+
Template.indent([
|
149
|
+
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
|
150
|
+
"var realSrc = event && event.target && event.target.src;",
|
151
|
+
"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
|
152
|
+
"error.type = errorType;",
|
153
|
+
"error.request = realSrc;",
|
154
|
+
"chunk[1](error);"
|
155
|
+
]),
|
156
|
+
"}",
|
157
|
+
"installedChunks[chunkId] = undefined;"
|
158
|
+
]),
|
159
|
+
"}"
|
160
|
+
]),
|
161
|
+
"};"
|
162
|
+
]);
|
163
|
+
}
|
164
|
+
);
|
165
|
+
mainTemplate.hooks.requireEnsure.tap(
|
166
|
+
"JsonpMainTemplatePlugin",
|
167
|
+
(source, chunk, hash) => {
|
168
|
+
return Template.asString([
|
169
|
+
source,
|
170
|
+
"",
|
171
|
+
"// JSONP chunk loading for javascript",
|
172
|
+
"",
|
173
|
+
"var installedChunkData = installedChunks[chunkId];",
|
174
|
+
'if(installedChunkData !== 0) { // 0 means "already installed".',
|
175
|
+
Template.indent([
|
176
|
+
"",
|
177
|
+
'// a Promise means "currently loading".',
|
178
|
+
"if(installedChunkData) {",
|
179
|
+
Template.indent(["promises.push(installedChunkData[2]);"]),
|
180
|
+
"} else {",
|
181
|
+
Template.indent([
|
182
|
+
"// setup Promise in chunk cache",
|
183
|
+
"var promise = new Promise(function(resolve, reject) {",
|
184
|
+
Template.indent([
|
185
|
+
"installedChunkData = installedChunks[chunkId] = [resolve, reject];"
|
186
|
+
]),
|
187
|
+
"});",
|
188
|
+
"promises.push(installedChunkData[2] = promise);",
|
189
|
+
"",
|
190
|
+
"// start chunk loading",
|
191
|
+
"var head = document.getElementsByTagName('head')[0];",
|
192
|
+
mainTemplate.hooks.jsonpScript.call("", chunk, hash),
|
193
|
+
"head.appendChild(script);"
|
194
|
+
]),
|
195
|
+
"}"
|
196
|
+
]),
|
197
|
+
"}"
|
198
|
+
]);
|
199
|
+
}
|
200
|
+
);
|
201
|
+
mainTemplate.hooks.requireExtensions.tap(
|
202
|
+
"JsonpMainTemplatePlugin",
|
203
|
+
(source, chunk) => {
|
204
|
+
if (!needChunkOnDemandLoadingCode(chunk)) return source;
|
205
|
+
|
206
|
+
return Template.asString([
|
207
|
+
source,
|
208
|
+
"",
|
209
|
+
"// on error function for async loading",
|
210
|
+
`${
|
211
|
+
mainTemplate.requireFn
|
212
|
+
}.oe = function(err) { console.error(err); throw err; };`
|
213
|
+
]);
|
214
|
+
}
|
215
|
+
);
|
216
|
+
mainTemplate.hooks.bootstrap.tap(
|
217
|
+
"JsonpMainTemplatePlugin",
|
218
|
+
(source, chunk, hash) => {
|
219
|
+
if (needChunkLoadingCode(chunk)) {
|
220
|
+
const withDefer = needEntryDeferringCode(chunk);
|
221
|
+
return Template.asString([
|
222
|
+
source,
|
223
|
+
"",
|
224
|
+
"// install a JSONP callback for chunk loading",
|
225
|
+
"function webpackJsonpCallback(data) {",
|
226
|
+
Template.indent([
|
227
|
+
"var chunkIds = data[0];",
|
228
|
+
"var moreModules = data[1];",
|
229
|
+
withDefer ? "var executeModules = data[2];" : "",
|
230
|
+
'// add "moreModules" to the modules object,',
|
231
|
+
'// then flag all "chunkIds" as loaded and fire callback',
|
232
|
+
"var moduleId, chunkId, i = 0, resolves = [];",
|
233
|
+
"for(;i < chunkIds.length; i++) {",
|
234
|
+
Template.indent([
|
235
|
+
"chunkId = chunkIds[i];",
|
236
|
+
"if(installedChunks[chunkId]) {",
|
237
|
+
Template.indent("resolves.push(installedChunks[chunkId][0]);"),
|
238
|
+
"}",
|
239
|
+
"installedChunks[chunkId] = 0;"
|
240
|
+
]),
|
241
|
+
"}",
|
242
|
+
"for(moduleId in moreModules) {",
|
243
|
+
Template.indent([
|
244
|
+
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
245
|
+
Template.indent(
|
246
|
+
mainTemplate.renderAddModule(
|
247
|
+
hash,
|
248
|
+
chunk,
|
249
|
+
"moduleId",
|
250
|
+
"moreModules[moduleId]"
|
251
|
+
)
|
252
|
+
),
|
253
|
+
"}"
|
254
|
+
]),
|
255
|
+
"}",
|
256
|
+
"if(parentJsonpFunction) parentJsonpFunction(data);",
|
257
|
+
"while(resolves.length) {",
|
258
|
+
Template.indent("resolves.shift()();"),
|
259
|
+
"}",
|
260
|
+
withDefer
|
261
|
+
? Template.asString([
|
262
|
+
"",
|
263
|
+
"// add entry modules from loaded chunk to deferred list",
|
264
|
+
"deferredModules.push.apply(deferredModules, executeModules || []);",
|
265
|
+
"",
|
266
|
+
"// run deferred modules when all chunks ready",
|
267
|
+
"return checkDeferredModules();"
|
268
|
+
])
|
269
|
+
: ""
|
270
|
+
]),
|
271
|
+
"};",
|
272
|
+
withDefer
|
273
|
+
? Template.asString([
|
274
|
+
"function checkDeferredModules() {",
|
275
|
+
Template.indent([
|
276
|
+
"var result;",
|
277
|
+
"for(var i = 0; i < deferredModules.length; i++) {",
|
278
|
+
Template.indent([
|
279
|
+
"var deferredModule = deferredModules[i];",
|
280
|
+
"var fulfilled = true;",
|
281
|
+
"for(var j = 1; j < deferredModule.length; j++) {",
|
282
|
+
Template.indent([
|
283
|
+
"var depId = deferredModule[j];",
|
284
|
+
"if(installedChunks[depId] !== 0) fulfilled = false;"
|
285
|
+
]),
|
286
|
+
"}",
|
287
|
+
"if(fulfilled) {",
|
288
|
+
Template.indent([
|
289
|
+
"deferredModules.splice(i--, 1);",
|
290
|
+
"result = " +
|
291
|
+
mainTemplate.requireFn +
|
292
|
+
"(" +
|
293
|
+
mainTemplate.requireFn +
|
294
|
+
".s = deferredModule[0]);"
|
295
|
+
]),
|
296
|
+
"}"
|
297
|
+
]),
|
298
|
+
"}",
|
299
|
+
"return result;"
|
300
|
+
]),
|
301
|
+
"}"
|
302
|
+
])
|
303
|
+
: ""
|
304
|
+
]);
|
305
|
+
}
|
306
|
+
return source;
|
307
|
+
}
|
308
|
+
);
|
309
|
+
mainTemplate.hooks.beforeStartup.tap(
|
310
|
+
"JsonpMainTemplatePlugin",
|
311
|
+
(source, chunk, hash) => {
|
312
|
+
if (needChunkLoadingCode(chunk)) {
|
313
|
+
var jsonpFunction = mainTemplate.outputOptions.jsonpFunction;
|
314
|
+
var globalObject = mainTemplate.outputOptions.globalObject;
|
315
|
+
return Template.asString([
|
316
|
+
`var jsonpArray = ${globalObject}[${JSON.stringify(
|
317
|
+
jsonpFunction
|
318
|
+
)}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`,
|
319
|
+
"var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);",
|
320
|
+
"jsonpArray.push = webpackJsonpCallback;",
|
321
|
+
"jsonpArray = jsonpArray.slice();",
|
322
|
+
"for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);",
|
323
|
+
"var parentJsonpFunction = oldJsonpFunction;",
|
324
|
+
"",
|
325
|
+
source
|
326
|
+
]);
|
327
|
+
}
|
328
|
+
return source;
|
329
|
+
}
|
330
|
+
);
|
331
|
+
mainTemplate.hooks.startup.tap(
|
332
|
+
"JsonpMainTemplatePlugin",
|
333
|
+
(source, chunk, hash) => {
|
334
|
+
if (needEntryDeferringCode(chunk)) {
|
335
|
+
if (chunk.hasEntryModule()) {
|
336
|
+
const entries = [chunk.entryModule].filter(Boolean).map(m =>
|
337
|
+
[m.id].concat(
|
338
|
+
Array.from(chunk.groupsIterable)[0]
|
339
|
+
.chunks.filter(c => c !== chunk)
|
340
|
+
.map(c => c.id)
|
341
|
+
)
|
342
|
+
);
|
343
|
+
return Template.asString([
|
344
|
+
"// add entry module to deferred list",
|
345
|
+
`deferredModules.push(${entries
|
346
|
+
.map(e => JSON.stringify(e))
|
347
|
+
.join(", ")});`,
|
348
|
+
"// run deferred modules when ready",
|
349
|
+
"return checkDeferredModules();"
|
350
|
+
]);
|
351
|
+
} else {
|
352
|
+
return Template.asString([
|
353
|
+
"// run deferred modules from other chunks",
|
354
|
+
"checkDeferredModules();"
|
355
|
+
]);
|
356
|
+
}
|
357
|
+
}
|
358
|
+
return source;
|
359
|
+
}
|
360
|
+
);
|
361
|
+
mainTemplate.hooks.hotBootstrap.tap(
|
362
|
+
"JsonpMainTemplatePlugin",
|
363
|
+
(source, chunk, hash) => {
|
364
|
+
const globalObject = mainTemplate.outputOptions.globalObject;
|
365
|
+
const hotUpdateChunkFilename =
|
366
|
+
mainTemplate.outputOptions.hotUpdateChunkFilename;
|
367
|
+
const hotUpdateMainFilename =
|
368
|
+
mainTemplate.outputOptions.hotUpdateMainFilename;
|
369
|
+
const crossOriginLoading =
|
370
|
+
mainTemplate.outputOptions.crossOriginLoading;
|
371
|
+
const hotUpdateFunction = mainTemplate.outputOptions.hotUpdateFunction;
|
372
|
+
const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(
|
373
|
+
JSON.stringify(hotUpdateChunkFilename),
|
374
|
+
{
|
375
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
376
|
+
hashWithLength: length =>
|
377
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
378
|
+
chunk: {
|
379
|
+
id: '" + chunkId + "'
|
380
|
+
}
|
381
|
+
}
|
382
|
+
);
|
383
|
+
const currentHotUpdateMainFilename = mainTemplate.getAssetPath(
|
384
|
+
JSON.stringify(hotUpdateMainFilename),
|
385
|
+
{
|
386
|
+
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
387
|
+
hashWithLength: length =>
|
388
|
+
`" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
|
389
|
+
}
|
390
|
+
);
|
391
|
+
const runtimeSource = Template.getFunctionContent(
|
392
|
+
require("./JsonpMainTemplate.runtime.js")
|
393
|
+
)
|
394
|
+
.replace(/\/\/\$semicolon/g, ";")
|
395
|
+
.replace(/\$require\$/g, mainTemplate.requireFn)
|
396
|
+
.replace(
|
397
|
+
/\$crossOriginLoading\$/g,
|
398
|
+
crossOriginLoading
|
399
|
+
? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}`
|
400
|
+
: ""
|
401
|
+
)
|
402
|
+
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
403
|
+
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
|
404
|
+
.replace(/\$hash\$/g, JSON.stringify(hash));
|
405
|
+
return `${source}
|
406
|
+
function hotDisposeChunk(chunkId) {
|
407
|
+
delete installedChunks[chunkId];
|
408
|
+
}
|
409
|
+
var parentHotUpdateCallback = ${globalObject}[${JSON.stringify(
|
410
|
+
hotUpdateFunction
|
411
|
+
)}];
|
412
|
+
${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
413
|
+
}
|
414
|
+
);
|
415
|
+
mainTemplate.hooks.hash.tap("JsonpMainTemplatePlugin", hash => {
|
416
|
+
hash.update("jsonp");
|
417
|
+
hash.update("5");
|
418
|
+
hash.update(`${mainTemplate.outputOptions.globalObject}`);
|
419
|
+
hash.update(`${mainTemplate.outputOptions.chunkFilename}`);
|
420
|
+
hash.update(`${mainTemplate.outputOptions.jsonpFunction}`);
|
421
|
+
hash.update(`${mainTemplate.outputOptions.hotUpdateFunction}`);
|
422
|
+
});
|
423
|
+
}
|
424
|
+
}
|
425
|
+
module.exports = JsonpMainTemplatePlugin;
|