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/Compiler.js
CHANGED
@@ -1,478 +1,493 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const asyncLib = require("neo-async");
|
8
|
-
const path = require("path");
|
9
|
-
const util = require("util");
|
10
|
-
const
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
const
|
19
|
-
const
|
20
|
-
const
|
21
|
-
const
|
22
|
-
|
23
|
-
const
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
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
|
-
case "
|
64
|
-
case "
|
65
|
-
case "
|
66
|
-
case "
|
67
|
-
case "after-
|
68
|
-
case "
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
this.
|
79
|
-
this.
|
80
|
-
|
81
|
-
|
82
|
-
this.
|
83
|
-
this.
|
84
|
-
|
85
|
-
this.
|
86
|
-
|
87
|
-
|
88
|
-
this.
|
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
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
this.
|
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
|
-
stats
|
182
|
-
stats.
|
183
|
-
|
184
|
-
|
185
|
-
return
|
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
|
-
this.
|
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
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
this.
|
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
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
childCompiler.
|
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
|
-
return
|
448
|
-
}
|
449
|
-
|
450
|
-
|
451
|
-
const
|
452
|
-
this.hooks.
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
this.
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const asyncLib = require("neo-async");
|
8
|
+
const path = require("path");
|
9
|
+
const util = require("util");
|
10
|
+
const {
|
11
|
+
Tapable,
|
12
|
+
SyncHook,
|
13
|
+
SyncBailHook,
|
14
|
+
AsyncParallelHook,
|
15
|
+
AsyncSeriesHook
|
16
|
+
} = require("tapable");
|
17
|
+
|
18
|
+
const Compilation = require("./Compilation");
|
19
|
+
const Stats = require("./Stats");
|
20
|
+
const Watching = require("./Watching");
|
21
|
+
const NormalModuleFactory = require("./NormalModuleFactory");
|
22
|
+
const ContextModuleFactory = require("./ContextModuleFactory");
|
23
|
+
const ResolverFactory = require("./ResolverFactory");
|
24
|
+
|
25
|
+
const RequestShortener = require("./RequestShortener");
|
26
|
+
const { makePathsRelative } = require("./util/identifier");
|
27
|
+
const ConcurrentCompilationError = require("./ConcurrentCompilationError");
|
28
|
+
|
29
|
+
class Compiler extends Tapable {
|
30
|
+
constructor(context) {
|
31
|
+
super();
|
32
|
+
this.hooks = {
|
33
|
+
shouldEmit: new SyncBailHook(["compilation"]),
|
34
|
+
done: new AsyncSeriesHook(["stats"]),
|
35
|
+
additionalPass: new AsyncSeriesHook([]),
|
36
|
+
beforeRun: new AsyncSeriesHook(["compilation"]),
|
37
|
+
run: new AsyncSeriesHook(["compilation"]),
|
38
|
+
emit: new AsyncSeriesHook(["compilation"]),
|
39
|
+
afterEmit: new AsyncSeriesHook(["compilation"]),
|
40
|
+
thisCompilation: new SyncHook(["compilation", "params"]),
|
41
|
+
compilation: new SyncHook(["compilation", "params"]),
|
42
|
+
normalModuleFactory: new SyncHook(["normalModuleFactory"]),
|
43
|
+
contextModuleFactory: new SyncHook(["contextModulefactory"]),
|
44
|
+
beforeCompile: new AsyncSeriesHook(["params"]),
|
45
|
+
compile: new SyncHook(["params"]),
|
46
|
+
make: new AsyncParallelHook(["compilation"]),
|
47
|
+
afterCompile: new AsyncSeriesHook(["compilation"]),
|
48
|
+
watchRun: new AsyncSeriesHook(["compiler"]),
|
49
|
+
failed: new SyncHook(["error"]),
|
50
|
+
invalid: new SyncHook(["filename", "changeTime"]),
|
51
|
+
watchClose: new SyncHook([]),
|
52
|
+
|
53
|
+
// TODO the following hooks are weirdly located here
|
54
|
+
// TODO move them for webpack 5
|
55
|
+
environment: new SyncHook([]),
|
56
|
+
afterEnvironment: new SyncHook([]),
|
57
|
+
afterPlugins: new SyncHook(["compiler"]),
|
58
|
+
afterResolvers: new SyncHook(["compiler"]),
|
59
|
+
entryOption: new SyncBailHook(["context", "entry"])
|
60
|
+
};
|
61
|
+
this._pluginCompat.tap("Compiler", options => {
|
62
|
+
switch (options.name) {
|
63
|
+
case "additional-pass":
|
64
|
+
case "before-run":
|
65
|
+
case "run":
|
66
|
+
case "emit":
|
67
|
+
case "after-emit":
|
68
|
+
case "before-compile":
|
69
|
+
case "make":
|
70
|
+
case "after-compile":
|
71
|
+
case "watch-run":
|
72
|
+
options.async = true;
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
});
|
76
|
+
|
77
|
+
this.outputPath = "";
|
78
|
+
this.outputFileSystem = null;
|
79
|
+
this.inputFileSystem = null;
|
80
|
+
|
81
|
+
this.recordsInputPath = null;
|
82
|
+
this.recordsOutputPath = null;
|
83
|
+
this.records = {};
|
84
|
+
|
85
|
+
this.fileTimestamps = new Map();
|
86
|
+
this.contextTimestamps = new Map();
|
87
|
+
|
88
|
+
this.resolverFactory = new ResolverFactory();
|
89
|
+
|
90
|
+
// TODO remove in webpack 5
|
91
|
+
this.resolvers = {
|
92
|
+
normal: {
|
93
|
+
plugins: util.deprecate((hook, fn) => {
|
94
|
+
this.resolverFactory.plugin("resolver normal", resolver => {
|
95
|
+
resolver.plugin(hook, fn);
|
96
|
+
});
|
97
|
+
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
98
|
+
apply: util.deprecate((...args) => {
|
99
|
+
this.resolverFactory.plugin("resolver normal", resolver => {
|
100
|
+
resolver.apply(...args);
|
101
|
+
});
|
102
|
+
}, "webpack: Using compiler.resolvers.normal is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver normal", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
103
|
+
},
|
104
|
+
loader: {
|
105
|
+
plugins: util.deprecate((hook, fn) => {
|
106
|
+
this.resolverFactory.plugin("resolver loader", resolver => {
|
107
|
+
resolver.plugin(hook, fn);
|
108
|
+
});
|
109
|
+
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
110
|
+
apply: util.deprecate((...args) => {
|
111
|
+
this.resolverFactory.plugin("resolver loader", resolver => {
|
112
|
+
resolver.apply(...args);
|
113
|
+
});
|
114
|
+
}, "webpack: Using compiler.resolvers.loader is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver loader", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
115
|
+
},
|
116
|
+
context: {
|
117
|
+
plugins: util.deprecate((hook, fn) => {
|
118
|
+
this.resolverFactory.plugin("resolver context", resolver => {
|
119
|
+
resolver.plugin(hook, fn);
|
120
|
+
});
|
121
|
+
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.plugin(/* … */);\n}); instead.'),
|
122
|
+
apply: util.deprecate((...args) => {
|
123
|
+
this.resolverFactory.plugin("resolver context", resolver => {
|
124
|
+
resolver.apply(...args);
|
125
|
+
});
|
126
|
+
}, "webpack: Using compiler.resolvers.context is deprecated.\n" + 'Use compiler.resolverFactory.plugin("resolver context", resolver => {\n resolver.apply(/* … */);\n}); instead.')
|
127
|
+
}
|
128
|
+
};
|
129
|
+
|
130
|
+
this.options = {};
|
131
|
+
|
132
|
+
this.context = context;
|
133
|
+
|
134
|
+
this.requestShortener = new RequestShortener(context);
|
135
|
+
|
136
|
+
this.running = false;
|
137
|
+
}
|
138
|
+
|
139
|
+
watch(watchOptions, handler) {
|
140
|
+
if (this.running) return handler(new ConcurrentCompilationError());
|
141
|
+
|
142
|
+
this.running = true;
|
143
|
+
this.fileTimestamps = new Map();
|
144
|
+
this.contextTimestamps = new Map();
|
145
|
+
return new Watching(this, watchOptions, handler);
|
146
|
+
}
|
147
|
+
|
148
|
+
run(callback) {
|
149
|
+
if (this.running) return callback(new ConcurrentCompilationError());
|
150
|
+
|
151
|
+
const finalCallback = (err, stats) => {
|
152
|
+
this.running = false;
|
153
|
+
|
154
|
+
if (callback !== undefined) return callback(err, stats);
|
155
|
+
};
|
156
|
+
|
157
|
+
const startTime = Date.now();
|
158
|
+
|
159
|
+
this.running = true;
|
160
|
+
|
161
|
+
const onCompiled = (err, compilation) => {
|
162
|
+
if (err) return finalCallback(err);
|
163
|
+
|
164
|
+
if (this.hooks.shouldEmit.call(compilation) === false) {
|
165
|
+
const stats = new Stats(compilation);
|
166
|
+
stats.startTime = startTime;
|
167
|
+
stats.endTime = Date.now();
|
168
|
+
this.hooks.done.callAsync(stats, err => {
|
169
|
+
if (err) return finalCallback(err);
|
170
|
+
return finalCallback(null, stats);
|
171
|
+
});
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
|
175
|
+
this.emitAssets(compilation, err => {
|
176
|
+
if (err) return finalCallback(err);
|
177
|
+
|
178
|
+
if (compilation.hooks.needAdditionalPass.call()) {
|
179
|
+
compilation.needAdditionalPass = true;
|
180
|
+
|
181
|
+
const stats = new Stats(compilation);
|
182
|
+
stats.startTime = startTime;
|
183
|
+
stats.endTime = Date.now();
|
184
|
+
this.hooks.done.callAsync(stats, err => {
|
185
|
+
if (err) return finalCallback(err);
|
186
|
+
|
187
|
+
this.hooks.additionalPass.callAsync(err => {
|
188
|
+
if (err) return finalCallback(err);
|
189
|
+
this.compile(onCompiled);
|
190
|
+
});
|
191
|
+
});
|
192
|
+
return;
|
193
|
+
}
|
194
|
+
|
195
|
+
this.emitRecords(err => {
|
196
|
+
if (err) return finalCallback(err);
|
197
|
+
|
198
|
+
const stats = new Stats(compilation);
|
199
|
+
stats.startTime = startTime;
|
200
|
+
stats.endTime = Date.now();
|
201
|
+
this.hooks.done.callAsync(stats, err => {
|
202
|
+
if (err) return finalCallback(err);
|
203
|
+
return finalCallback(null, stats);
|
204
|
+
});
|
205
|
+
});
|
206
|
+
});
|
207
|
+
};
|
208
|
+
|
209
|
+
this.hooks.beforeRun.callAsync(this, err => {
|
210
|
+
if (err) return finalCallback(err);
|
211
|
+
|
212
|
+
this.hooks.run.callAsync(this, err => {
|
213
|
+
if (err) return finalCallback(err);
|
214
|
+
|
215
|
+
this.readRecords(err => {
|
216
|
+
if (err) return finalCallback(err);
|
217
|
+
|
218
|
+
this.compile(onCompiled);
|
219
|
+
});
|
220
|
+
});
|
221
|
+
});
|
222
|
+
}
|
223
|
+
|
224
|
+
runAsChild(callback) {
|
225
|
+
this.compile((err, compilation) => {
|
226
|
+
if (err) return callback(err);
|
227
|
+
|
228
|
+
this.parentCompilation.children.push(compilation);
|
229
|
+
for (const name of Object.keys(compilation.assets)) {
|
230
|
+
this.parentCompilation.assets[name] = compilation.assets[name];
|
231
|
+
}
|
232
|
+
|
233
|
+
const entries = Array.from(
|
234
|
+
compilation.entrypoints.values(),
|
235
|
+
ep => ep.chunks
|
236
|
+
).reduce((array, chunks) => {
|
237
|
+
return array.concat(chunks);
|
238
|
+
}, []);
|
239
|
+
|
240
|
+
return callback(null, entries, compilation);
|
241
|
+
});
|
242
|
+
}
|
243
|
+
|
244
|
+
purgeInputFileSystem() {
|
245
|
+
if (this.inputFileSystem && this.inputFileSystem.purge)
|
246
|
+
this.inputFileSystem.purge();
|
247
|
+
}
|
248
|
+
|
249
|
+
emitAssets(compilation, callback) {
|
250
|
+
let outputPath;
|
251
|
+
|
252
|
+
const emitFiles = err => {
|
253
|
+
if (err) return callback(err);
|
254
|
+
|
255
|
+
asyncLib.forEach(
|
256
|
+
compilation.assets,
|
257
|
+
(source, file, callback) => {
|
258
|
+
let targetFile = file;
|
259
|
+
const queryStringIdx = targetFile.indexOf("?");
|
260
|
+
if (queryStringIdx >= 0) {
|
261
|
+
targetFile = targetFile.substr(0, queryStringIdx);
|
262
|
+
}
|
263
|
+
|
264
|
+
const writeOut = err => {
|
265
|
+
if (err) return callback(err);
|
266
|
+
const targetPath = this.outputFileSystem.join(
|
267
|
+
outputPath,
|
268
|
+
targetFile
|
269
|
+
);
|
270
|
+
if (source.existsAt === targetPath) {
|
271
|
+
source.emitted = false;
|
272
|
+
return callback();
|
273
|
+
}
|
274
|
+
let content = source.source();
|
275
|
+
|
276
|
+
if (!Buffer.isBuffer(content)) {
|
277
|
+
content = Buffer.from(content, "utf8");
|
278
|
+
}
|
279
|
+
|
280
|
+
source.existsAt = targetPath;
|
281
|
+
source.emitted = true;
|
282
|
+
this.outputFileSystem.writeFile(targetPath, content, callback);
|
283
|
+
};
|
284
|
+
|
285
|
+
if (targetFile.match(/\/|\\/)) {
|
286
|
+
const dir = path.dirname(targetFile);
|
287
|
+
this.outputFileSystem.mkdirp(
|
288
|
+
this.outputFileSystem.join(outputPath, dir),
|
289
|
+
writeOut
|
290
|
+
);
|
291
|
+
} else writeOut();
|
292
|
+
},
|
293
|
+
err => {
|
294
|
+
if (err) return callback(err);
|
295
|
+
|
296
|
+
this.hooks.afterEmit.callAsync(compilation, err => {
|
297
|
+
if (err) return callback(err);
|
298
|
+
|
299
|
+
return callback();
|
300
|
+
});
|
301
|
+
}
|
302
|
+
);
|
303
|
+
};
|
304
|
+
|
305
|
+
this.hooks.emit.callAsync(compilation, err => {
|
306
|
+
if (err) return callback(err);
|
307
|
+
outputPath = compilation.getPath(this.outputPath);
|
308
|
+
this.outputFileSystem.mkdirp(outputPath, emitFiles);
|
309
|
+
});
|
310
|
+
}
|
311
|
+
|
312
|
+
emitRecords(callback) {
|
313
|
+
if (!this.recordsOutputPath) return callback();
|
314
|
+
const idx1 = this.recordsOutputPath.lastIndexOf("/");
|
315
|
+
const idx2 = this.recordsOutputPath.lastIndexOf("\\");
|
316
|
+
let recordsOutputPathDirectory = null;
|
317
|
+
if (idx1 > idx2)
|
318
|
+
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1);
|
319
|
+
if (idx1 < idx2)
|
320
|
+
recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2);
|
321
|
+
|
322
|
+
const writeFile = () => {
|
323
|
+
this.outputFileSystem.writeFile(
|
324
|
+
this.recordsOutputPath,
|
325
|
+
JSON.stringify(this.records, undefined, 2),
|
326
|
+
callback
|
327
|
+
);
|
328
|
+
};
|
329
|
+
|
330
|
+
if (!recordsOutputPathDirectory) return writeFile();
|
331
|
+
this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => {
|
332
|
+
if (err) return callback(err);
|
333
|
+
writeFile();
|
334
|
+
});
|
335
|
+
}
|
336
|
+
|
337
|
+
readRecords(callback) {
|
338
|
+
if (!this.recordsInputPath) {
|
339
|
+
this.records = {};
|
340
|
+
return callback();
|
341
|
+
}
|
342
|
+
this.inputFileSystem.stat(this.recordsInputPath, err => {
|
343
|
+
// It doesn't exist
|
344
|
+
// We can ignore this.
|
345
|
+
if (err) return callback();
|
346
|
+
|
347
|
+
this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => {
|
348
|
+
if (err) return callback(err);
|
349
|
+
|
350
|
+
try {
|
351
|
+
this.records = JSON.parse(content.toString("utf-8"));
|
352
|
+
} catch (e) {
|
353
|
+
e.message = "Cannot parse records: " + e.message;
|
354
|
+
return callback(e);
|
355
|
+
}
|
356
|
+
|
357
|
+
return callback();
|
358
|
+
});
|
359
|
+
});
|
360
|
+
}
|
361
|
+
|
362
|
+
createChildCompiler(
|
363
|
+
compilation,
|
364
|
+
compilerName,
|
365
|
+
compilerIndex,
|
366
|
+
outputOptions,
|
367
|
+
plugins
|
368
|
+
) {
|
369
|
+
const childCompiler = new Compiler(this.context);
|
370
|
+
if (Array.isArray(plugins)) {
|
371
|
+
for (const plugin of plugins) plugin.apply(childCompiler);
|
372
|
+
}
|
373
|
+
for (const name in this.hooks) {
|
374
|
+
if (
|
375
|
+
![
|
376
|
+
"make",
|
377
|
+
"compile",
|
378
|
+
"emit",
|
379
|
+
"afterEmit",
|
380
|
+
"invalid",
|
381
|
+
"done",
|
382
|
+
"thisCompilation"
|
383
|
+
].includes(name)
|
384
|
+
) {
|
385
|
+
if (childCompiler.hooks[name])
|
386
|
+
childCompiler.hooks[name].taps = this.hooks[name].taps.slice();
|
387
|
+
}
|
388
|
+
}
|
389
|
+
childCompiler.name = compilerName;
|
390
|
+
childCompiler.outputPath = this.outputPath;
|
391
|
+
childCompiler.inputFileSystem = this.inputFileSystem;
|
392
|
+
childCompiler.outputFileSystem = null;
|
393
|
+
childCompiler.resolverFactory = this.resolverFactory;
|
394
|
+
childCompiler.fileTimestamps = this.fileTimestamps;
|
395
|
+
childCompiler.contextTimestamps = this.contextTimestamps;
|
396
|
+
|
397
|
+
const relativeCompilerName = makePathsRelative(this.context, compilerName);
|
398
|
+
if (!this.records[relativeCompilerName])
|
399
|
+
this.records[relativeCompilerName] = [];
|
400
|
+
if (this.records[relativeCompilerName][compilerIndex])
|
401
|
+
childCompiler.records = this.records[relativeCompilerName][compilerIndex];
|
402
|
+
else this.records[relativeCompilerName].push((childCompiler.records = {}));
|
403
|
+
|
404
|
+
childCompiler.options = Object.create(this.options);
|
405
|
+
childCompiler.options.output = Object.create(childCompiler.options.output);
|
406
|
+
for (const name in outputOptions) {
|
407
|
+
childCompiler.options.output[name] = outputOptions[name];
|
408
|
+
}
|
409
|
+
childCompiler.parentCompilation = compilation;
|
410
|
+
|
411
|
+
compilation.hooks.childCompiler.call(
|
412
|
+
childCompiler,
|
413
|
+
compilerName,
|
414
|
+
compilerIndex
|
415
|
+
);
|
416
|
+
|
417
|
+
return childCompiler;
|
418
|
+
}
|
419
|
+
|
420
|
+
isChild() {
|
421
|
+
return !!this.parentCompilation;
|
422
|
+
}
|
423
|
+
|
424
|
+
createCompilation() {
|
425
|
+
return new Compilation(this);
|
426
|
+
}
|
427
|
+
|
428
|
+
newCompilation(params) {
|
429
|
+
const compilation = this.createCompilation();
|
430
|
+
compilation.fileTimestamps = this.fileTimestamps;
|
431
|
+
compilation.contextTimestamps = this.contextTimestamps;
|
432
|
+
compilation.name = this.name;
|
433
|
+
compilation.records = this.records;
|
434
|
+
compilation.compilationDependencies = params.compilationDependencies;
|
435
|
+
this.hooks.thisCompilation.call(compilation, params);
|
436
|
+
this.hooks.compilation.call(compilation, params);
|
437
|
+
return compilation;
|
438
|
+
}
|
439
|
+
|
440
|
+
createNormalModuleFactory() {
|
441
|
+
const normalModuleFactory = new NormalModuleFactory(
|
442
|
+
this.options.context,
|
443
|
+
this.resolverFactory,
|
444
|
+
this.options.module || {}
|
445
|
+
);
|
446
|
+
this.hooks.normalModuleFactory.call(normalModuleFactory);
|
447
|
+
return normalModuleFactory;
|
448
|
+
}
|
449
|
+
|
450
|
+
createContextModuleFactory() {
|
451
|
+
const contextModuleFactory = new ContextModuleFactory(this.resolverFactory);
|
452
|
+
this.hooks.contextModuleFactory.call(contextModuleFactory);
|
453
|
+
return contextModuleFactory;
|
454
|
+
}
|
455
|
+
|
456
|
+
newCompilationParams() {
|
457
|
+
const params = {
|
458
|
+
normalModuleFactory: this.createNormalModuleFactory(),
|
459
|
+
contextModuleFactory: this.createContextModuleFactory(),
|
460
|
+
compilationDependencies: new Set()
|
461
|
+
};
|
462
|
+
return params;
|
463
|
+
}
|
464
|
+
|
465
|
+
compile(callback) {
|
466
|
+
const params = this.newCompilationParams();
|
467
|
+
this.hooks.beforeCompile.callAsync(params, err => {
|
468
|
+
if (err) return callback(err);
|
469
|
+
|
470
|
+
this.hooks.compile.call(params);
|
471
|
+
|
472
|
+
const compilation = this.newCompilation(params);
|
473
|
+
|
474
|
+
this.hooks.make.callAsync(compilation, err => {
|
475
|
+
if (err) return callback(err);
|
476
|
+
|
477
|
+
compilation.finish();
|
478
|
+
|
479
|
+
compilation.seal(err => {
|
480
|
+
if (err) return callback(err);
|
481
|
+
|
482
|
+
this.hooks.afterCompile.callAsync(compilation, err => {
|
483
|
+
if (err) return callback(err);
|
484
|
+
|
485
|
+
return callback(null, compilation);
|
486
|
+
});
|
487
|
+
});
|
488
|
+
});
|
489
|
+
});
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
module.exports = Compiler;
|