webpack 4.14.0 → 4.16.1
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/LICENSE +20 -20
- package/README.md +5 -2
- package/bin/webpack.js +7 -2
- package/buildin/amd-define.js +3 -3
- package/buildin/amd-options.js +2 -2
- package/buildin/system.js +7 -7
- package/hot/dev-server.js +2 -2
- package/hot/emitter.js +2 -2
- package/hot/only-dev-server.js +2 -2
- package/hot/poll.js +5 -2
- package/hot/signal.js +2 -2
- package/lib/AsyncDependenciesBlock.js +44 -0
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/Chunk.js +56 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/ChunkTemplate.js +14 -2
- package/lib/CommentCompilationWarning.js +3 -3
- package/lib/CompatibilityPlugin.js +1 -1
- package/lib/Compilation.js +442 -37
- package/lib/Compiler.js +57 -4
- package/lib/ContextModule.js +23 -16
- package/lib/DefinePlugin.js +49 -0
- package/lib/DelegatedModule.js +9 -1
- package/lib/DelegatedModuleFactoryPlugin.js +7 -1
- package/lib/DependenciesBlock.js +36 -3
- package/lib/DependenciesBlockVariable.js +22 -0
- package/lib/Dependency.js +33 -6
- package/lib/DllEntryPlugin.js +4 -1
- package/lib/DynamicEntryPlugin.js +21 -1
- package/lib/EntryOptionPlugin.js +12 -0
- package/lib/Entrypoint.js +1 -1
- package/lib/EnvironmentPlugin.js +8 -1
- package/lib/ExtendedAPIPlugin.js +8 -4
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/Generator.js +1 -1
- package/lib/GraphHelpers.js +2 -1
- package/lib/HotModuleReplacement.runtime.js +8 -5
- package/lib/HotModuleReplacementPlugin.js +115 -117
- package/lib/IgnorePlugin.js +1 -1
- package/lib/MainTemplate.js +19 -4
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +9 -3
- package/lib/ModuleReason.js +8 -0
- package/lib/MultiEntryPlugin.js +25 -3
- package/lib/NormalModule.js +5 -23
- package/lib/NullFactory.js +12 -12
- package/lib/OptionsApply.js +10 -10
- package/lib/RuleSet.js +3 -3
- package/lib/SingleEntryPlugin.js +20 -1
- package/lib/Stats.js +12 -5
- package/lib/Template.js +4 -1
- package/lib/UmdMainTemplatePlugin.js +12 -12
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WebpackError.js +4 -0
- package/lib/WebpackOptionsApply.js +92 -10
- package/lib/WebpackOptionsDefaulter.js +23 -6
- package/lib/WebpackOptionsValidationError.js +0 -1
- package/lib/compareLocations.js +13 -17
- package/lib/debug/ProfilingPlugin.js +5 -7
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -6
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +0 -2
- package/lib/dependencies/AMDRequireItemDependency.js +22 -22
- package/lib/dependencies/CommonJsRequireDependency.js +22 -22
- package/lib/dependencies/CriticalDependencyWarning.js +20 -20
- package/lib/dependencies/DelegatedSourceDependency.js +18 -18
- package/lib/dependencies/DllEntryDependency.js +20 -20
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/LoaderDependency.js +3 -0
- package/lib/dependencies/LoaderPlugin.js +21 -2
- package/lib/dependencies/LocalModule.js +23 -23
- package/lib/dependencies/ModuleDependency.js +3 -0
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
- package/lib/dependencies/MultiEntryDependency.js +5 -0
- package/lib/dependencies/PrefetchDependency.js +18 -18
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
- package/lib/dependencies/RequireResolveDependency.js +22 -22
- package/lib/dependencies/SingleEntryDependency.js +3 -0
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/formatLocation.js +55 -41
- package/lib/node/NodeMainTemplateAsync.runtime.js +1 -1
- package/lib/node/NodeMainTemplatePlugin.js +2 -2
- package/lib/node/NodeOutputFileSystem.js +22 -22
- package/lib/node/NodeSourcePlugin.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +1 -0
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +4 -2
- package/lib/optimize/SplitChunksPlugin.js +168 -18
- package/lib/util/Semaphore.js +12 -0
- package/lib/util/SetHelpers.js +4 -4
- package/lib/util/SortableSet.js +1 -1
- package/lib/util/cachedMerge.js +1 -1
- package/lib/util/createHash.js +15 -0
- package/lib/util/deterministicGrouping.js +251 -0
- package/lib/util/identifier.js +27 -0
- package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm/WasmMainTemplatePlugin.js +10 -4
- package/lib/wasm/WebAssemblyGenerator.js +12 -12
- package/lib/wasm/WebAssemblyInInitialChunkError.js +88 -0
- package/lib/wasm/WebAssemblyModulesPlugin.js +28 -0
- package/lib/web/JsonpMainTemplatePlugin.js +1 -1
- package/lib/web/WebEnvironmentPlugin.js +18 -18
- package/lib/webpack.js +4 -0
- package/lib/webpack.web.js +2 -2
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +1 -1
- package/package.json +27 -17
- package/schemas/WebpackOptions.json +71 -9
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
package/lib/ExtendedAPIPlugin.js
CHANGED
@@ -10,12 +10,16 @@ const ParserHelpers = require("./ParserHelpers");
|
|
10
10
|
const NullFactory = require("./NullFactory");
|
11
11
|
|
12
12
|
const REPLACEMENTS = {
|
13
|
-
|
14
|
-
|
13
|
+
// eslint-disable-next-line camelcase
|
14
|
+
__webpack_hash__: "__webpack_require__.h",
|
15
|
+
// eslint-disable-next-line camelcase
|
16
|
+
__webpack_chunkname__: "__webpack_require__.cn"
|
15
17
|
};
|
16
18
|
const REPLACEMENT_TYPES = {
|
17
|
-
|
18
|
-
|
19
|
+
// eslint-disable-next-line camelcase
|
20
|
+
__webpack_hash__: "string",
|
21
|
+
// eslint-disable-next-line camelcase
|
22
|
+
__webpack_chunkname__: "string"
|
19
23
|
};
|
20
24
|
|
21
25
|
class ExtendedAPIPlugin {
|
@@ -64,7 +64,7 @@ class ExternalModuleFactoryPlugin {
|
|
64
64
|
asyncFlag = true;
|
65
65
|
if (i >= externals.length) return callback();
|
66
66
|
handleExternals(externals[i++], handleExternalsAndCallback);
|
67
|
-
} while (!asyncFlag);
|
67
|
+
} while (!asyncFlag);
|
68
68
|
asyncFlag = false;
|
69
69
|
};
|
70
70
|
|
package/lib/Generator.js
CHANGED
@@ -25,7 +25,7 @@ class Generator {
|
|
25
25
|
* @returns {Source} generated code
|
26
26
|
*/
|
27
27
|
generate(module, dependencyTemplates, runtimeTemplate, type) {
|
28
|
-
throw new Error("Generator.generate: must be
|
28
|
+
throw new Error("Generator.generate: must be overridden");
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
package/lib/GraphHelpers.js
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
3
3
|
/** @typedef {import("./Module")} Module */
|
4
4
|
/** @typedef {import("./DependenciesBlock")} DependenciesBlock */
|
5
|
+
/** @typedef {import("./AsyncDependenciesBlock")} AsyncDependenciesBlock */
|
5
6
|
|
6
7
|
/**
|
7
8
|
* @param {ChunkGroup} chunkGroup the ChunkGroup to connect
|
@@ -47,7 +48,7 @@ const disconnectChunkAndModule = (chunk, module) => {
|
|
47
48
|
};
|
48
49
|
|
49
50
|
/**
|
50
|
-
* @param {
|
51
|
+
* @param {AsyncDependenciesBlock} depBlock DepBlock being tied to ChunkGroup
|
51
52
|
* @param {ChunkGroup} chunkGroup ChunkGroup being tied to DepBlock
|
52
53
|
* @returns {void}
|
53
54
|
*/
|
@@ -5,12 +5,15 @@
|
|
5
5
|
/*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
|
6
6
|
module.exports = function() {
|
7
7
|
var hotApplyOnUpdate = true;
|
8
|
-
|
8
|
+
// eslint-disable-next-line no-unused-vars
|
9
|
+
var hotCurrentHash = $hash$;
|
9
10
|
var hotRequestTimeout = $requestTimeout$;
|
10
11
|
var hotCurrentModuleData = {};
|
11
|
-
var hotCurrentChildModule;
|
12
|
-
|
13
|
-
var
|
12
|
+
var hotCurrentChildModule;
|
13
|
+
// eslint-disable-next-line no-unused-vars
|
14
|
+
var hotCurrentParents = [];
|
15
|
+
// eslint-disable-next-line no-unused-vars
|
16
|
+
var hotCurrentParentsTemp = [];
|
14
17
|
|
15
18
|
// eslint-disable-next-line no-unused-vars
|
16
19
|
function hotCreateRequire(moduleId) {
|
@@ -199,8 +202,8 @@ module.exports = function() {
|
|
199
202
|
});
|
200
203
|
hotUpdate = {};
|
201
204
|
/*foreachInstalledChunks*/
|
205
|
+
// eslint-disable-next-line no-lone-blocks
|
202
206
|
{
|
203
|
-
// eslint-disable-line no-lone-blocks
|
204
207
|
/*globals chunkId */
|
205
208
|
hotEnsureUpdateChunk(chunkId);
|
206
209
|
}
|
@@ -35,6 +35,118 @@ module.exports = class HotModuleReplacementPlugin {
|
|
35
35
|
return callback();
|
36
36
|
}
|
37
37
|
);
|
38
|
+
|
39
|
+
const addParserPlugins = (parser, parserOptions) => {
|
40
|
+
parser.hooks.expression
|
41
|
+
.for("__webpack_hash__")
|
42
|
+
.tap(
|
43
|
+
"HotModuleReplacementPlugin",
|
44
|
+
ParserHelpers.toConstantDependencyWithWebpackRequire(
|
45
|
+
parser,
|
46
|
+
"__webpack_require__.h()"
|
47
|
+
)
|
48
|
+
);
|
49
|
+
parser.hooks.evaluateTypeof
|
50
|
+
.for("__webpack_hash__")
|
51
|
+
.tap(
|
52
|
+
"HotModuleReplacementPlugin",
|
53
|
+
ParserHelpers.evaluateToString("string")
|
54
|
+
);
|
55
|
+
parser.hooks.evaluateIdentifier.for("module.hot").tap(
|
56
|
+
{
|
57
|
+
name: "HotModuleReplacementPlugin",
|
58
|
+
before: "NodeStuffPlugin"
|
59
|
+
},
|
60
|
+
expr => {
|
61
|
+
return ParserHelpers.evaluateToIdentifier(
|
62
|
+
"module.hot",
|
63
|
+
!!parser.state.compilation.hotUpdateChunkTemplate
|
64
|
+
)(expr);
|
65
|
+
}
|
66
|
+
);
|
67
|
+
// TODO webpack 5: refactor this, no custom hooks
|
68
|
+
if (!parser.hooks.hotAcceptCallback) {
|
69
|
+
parser.hooks.hotAcceptCallback = new SyncBailHook([
|
70
|
+
"expression",
|
71
|
+
"requests"
|
72
|
+
]);
|
73
|
+
}
|
74
|
+
if (!parser.hooks.hotAcceptWithoutCallback) {
|
75
|
+
parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
|
76
|
+
"expression",
|
77
|
+
"requests"
|
78
|
+
]);
|
79
|
+
}
|
80
|
+
parser.hooks.call
|
81
|
+
.for("module.hot.accept")
|
82
|
+
.tap("HotModuleReplacementPlugin", expr => {
|
83
|
+
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
84
|
+
return false;
|
85
|
+
}
|
86
|
+
if (expr.arguments.length >= 1) {
|
87
|
+
const arg = parser.evaluateExpression(expr.arguments[0]);
|
88
|
+
let params = [];
|
89
|
+
let requests = [];
|
90
|
+
if (arg.isString()) {
|
91
|
+
params = [arg];
|
92
|
+
} else if (arg.isArray()) {
|
93
|
+
params = arg.items.filter(param => param.isString());
|
94
|
+
}
|
95
|
+
if (params.length > 0) {
|
96
|
+
params.forEach((param, idx) => {
|
97
|
+
const request = param.string;
|
98
|
+
const dep = new ModuleHotAcceptDependency(request, param.range);
|
99
|
+
dep.optional = true;
|
100
|
+
dep.loc = Object.create(expr.loc);
|
101
|
+
dep.loc.index = idx;
|
102
|
+
parser.state.module.addDependency(dep);
|
103
|
+
requests.push(request);
|
104
|
+
});
|
105
|
+
if (expr.arguments.length > 1) {
|
106
|
+
parser.hooks.hotAcceptCallback.call(
|
107
|
+
expr.arguments[1],
|
108
|
+
requests
|
109
|
+
);
|
110
|
+
parser.walkExpression(expr.arguments[1]); // other args are ignored
|
111
|
+
return true;
|
112
|
+
} else {
|
113
|
+
parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
|
114
|
+
return true;
|
115
|
+
}
|
116
|
+
}
|
117
|
+
}
|
118
|
+
});
|
119
|
+
parser.hooks.call
|
120
|
+
.for("module.hot.decline")
|
121
|
+
.tap("HotModuleReplacementPlugin", expr => {
|
122
|
+
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
123
|
+
return false;
|
124
|
+
}
|
125
|
+
if (expr.arguments.length === 1) {
|
126
|
+
const arg = parser.evaluateExpression(expr.arguments[0]);
|
127
|
+
let params = [];
|
128
|
+
if (arg.isString()) {
|
129
|
+
params = [arg];
|
130
|
+
} else if (arg.isArray()) {
|
131
|
+
params = arg.items.filter(param => param.isString());
|
132
|
+
}
|
133
|
+
params.forEach((param, idx) => {
|
134
|
+
const dep = new ModuleHotDeclineDependency(
|
135
|
+
param.string,
|
136
|
+
param.range
|
137
|
+
);
|
138
|
+
dep.optional = true;
|
139
|
+
dep.loc = Object.create(expr.loc);
|
140
|
+
dep.loc.index = idx;
|
141
|
+
parser.state.module.addDependency(dep);
|
142
|
+
});
|
143
|
+
}
|
144
|
+
});
|
145
|
+
parser.hooks.expression
|
146
|
+
.for("module.hot")
|
147
|
+
.tap("HotModuleReplacementPlugin", ParserHelpers.skipTraversal);
|
148
|
+
};
|
149
|
+
|
38
150
|
compiler.hooks.compilation.tap(
|
39
151
|
"HotModuleReplacementPlugin",
|
40
152
|
(compilation, { normalModuleFactory }) => {
|
@@ -275,127 +387,13 @@ module.exports = class HotModuleReplacementPlugin {
|
|
275
387
|
}
|
276
388
|
);
|
277
389
|
|
278
|
-
const handler = (parser, parserOptions) => {
|
279
|
-
parser.hooks.expression
|
280
|
-
.for("__webpack_hash__")
|
281
|
-
.tap(
|
282
|
-
"HotModuleReplacementPlugin",
|
283
|
-
ParserHelpers.toConstantDependencyWithWebpackRequire(
|
284
|
-
parser,
|
285
|
-
"__webpack_require__.h()"
|
286
|
-
)
|
287
|
-
);
|
288
|
-
parser.hooks.evaluateTypeof
|
289
|
-
.for("__webpack_hash__")
|
290
|
-
.tap(
|
291
|
-
"HotModuleReplacementPlugin",
|
292
|
-
ParserHelpers.evaluateToString("string")
|
293
|
-
);
|
294
|
-
parser.hooks.evaluateIdentifier.for("module.hot").tap(
|
295
|
-
{
|
296
|
-
name: "HotModuleReplacementPlugin",
|
297
|
-
before: "NodeStuffPlugin"
|
298
|
-
},
|
299
|
-
expr => {
|
300
|
-
return ParserHelpers.evaluateToIdentifier(
|
301
|
-
"module.hot",
|
302
|
-
!!parser.state.compilation.hotUpdateChunkTemplate
|
303
|
-
)(expr);
|
304
|
-
}
|
305
|
-
);
|
306
|
-
// TODO webpack 5: refactor this, no custom hooks
|
307
|
-
if (!parser.hooks.hotAcceptCallback) {
|
308
|
-
parser.hooks.hotAcceptCallback = new SyncBailHook([
|
309
|
-
"expression",
|
310
|
-
"requests"
|
311
|
-
]);
|
312
|
-
}
|
313
|
-
if (!parser.hooks.hotAcceptWithoutCallback) {
|
314
|
-
parser.hooks.hotAcceptWithoutCallback = new SyncBailHook([
|
315
|
-
"expression",
|
316
|
-
"requests"
|
317
|
-
]);
|
318
|
-
}
|
319
|
-
parser.hooks.call
|
320
|
-
.for("module.hot.accept")
|
321
|
-
.tap("HotModuleReplacementPlugin", expr => {
|
322
|
-
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
323
|
-
return false;
|
324
|
-
}
|
325
|
-
if (expr.arguments.length >= 1) {
|
326
|
-
const arg = parser.evaluateExpression(expr.arguments[0]);
|
327
|
-
let params = [];
|
328
|
-
let requests = [];
|
329
|
-
if (arg.isString()) {
|
330
|
-
params = [arg];
|
331
|
-
} else if (arg.isArray()) {
|
332
|
-
params = arg.items.filter(param => param.isString());
|
333
|
-
}
|
334
|
-
if (params.length > 0) {
|
335
|
-
params.forEach((param, idx) => {
|
336
|
-
const request = param.string;
|
337
|
-
const dep = new ModuleHotAcceptDependency(
|
338
|
-
request,
|
339
|
-
param.range
|
340
|
-
);
|
341
|
-
dep.optional = true;
|
342
|
-
dep.loc = Object.create(expr.loc);
|
343
|
-
dep.loc.index = idx;
|
344
|
-
parser.state.module.addDependency(dep);
|
345
|
-
requests.push(request);
|
346
|
-
});
|
347
|
-
if (expr.arguments.length > 1) {
|
348
|
-
parser.hooks.hotAcceptCallback.call(
|
349
|
-
expr.arguments[1],
|
350
|
-
requests
|
351
|
-
);
|
352
|
-
parser.walkExpression(expr.arguments[1]); // other args are ignored
|
353
|
-
return true;
|
354
|
-
} else {
|
355
|
-
parser.hooks.hotAcceptWithoutCallback.call(expr, requests);
|
356
|
-
return true;
|
357
|
-
}
|
358
|
-
}
|
359
|
-
}
|
360
|
-
});
|
361
|
-
parser.hooks.call
|
362
|
-
.for("module.hot.decline")
|
363
|
-
.tap("HotModuleReplacementPlugin", expr => {
|
364
|
-
if (!parser.state.compilation.hotUpdateChunkTemplate) {
|
365
|
-
return false;
|
366
|
-
}
|
367
|
-
if (expr.arguments.length === 1) {
|
368
|
-
const arg = parser.evaluateExpression(expr.arguments[0]);
|
369
|
-
let params = [];
|
370
|
-
if (arg.isString()) {
|
371
|
-
params = [arg];
|
372
|
-
} else if (arg.isArray()) {
|
373
|
-
params = arg.items.filter(param => param.isString());
|
374
|
-
}
|
375
|
-
params.forEach((param, idx) => {
|
376
|
-
const dep = new ModuleHotDeclineDependency(
|
377
|
-
param.string,
|
378
|
-
param.range
|
379
|
-
);
|
380
|
-
dep.optional = true;
|
381
|
-
dep.loc = Object.create(expr.loc);
|
382
|
-
dep.loc.index = idx;
|
383
|
-
parser.state.module.addDependency(dep);
|
384
|
-
});
|
385
|
-
}
|
386
|
-
});
|
387
|
-
parser.hooks.expression
|
388
|
-
.for("module.hot")
|
389
|
-
.tap("HotModuleReplacementPlugin", ParserHelpers.skipTraversal);
|
390
|
-
};
|
391
|
-
|
392
390
|
// TODO add HMR support for javascript/esm
|
393
391
|
normalModuleFactory.hooks.parser
|
394
392
|
.for("javascript/auto")
|
395
|
-
.tap("HotModuleReplacementPlugin",
|
393
|
+
.tap("HotModuleReplacementPlugin", addParserPlugins);
|
396
394
|
normalModuleFactory.hooks.parser
|
397
395
|
.for("javascript/dynamic")
|
398
|
-
.tap("HotModuleReplacementPlugin",
|
396
|
+
.tap("HotModuleReplacementPlugin", addParserPlugins);
|
399
397
|
|
400
398
|
compilation.hooks.normalModuleLoader.tap(
|
401
399
|
"HotModuleReplacementPlugin",
|
@@ -409,5 +407,5 @@ module.exports = class HotModuleReplacementPlugin {
|
|
409
407
|
};
|
410
408
|
|
411
409
|
const hotInitCode = Template.getFunctionContent(
|
412
|
-
require("./HotModuleReplacement.runtime
|
410
|
+
require("./HotModuleReplacement.runtime")
|
413
411
|
);
|
package/lib/IgnorePlugin.js
CHANGED
package/lib/MainTemplate.js
CHANGED
@@ -19,15 +19,17 @@ const {
|
|
19
19
|
const Template = require("./Template");
|
20
20
|
|
21
21
|
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
22
|
+
/** @typedef {import("webpack-sources").Source} Source */
|
22
23
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
23
24
|
/** @typedef {import("./Chunk")} Chunk */
|
24
25
|
/** @typedef {import("./Module")} Module} */
|
25
|
-
/** @typedef {import("
|
26
|
+
/** @typedef {import("./util/createHash").Hash} Hash} */
|
27
|
+
/** @typedef {import("./Dependency").DependencyTemplate} DependencyTemplate} */
|
26
28
|
|
27
29
|
/**
|
28
30
|
* @typedef {Object} RenderManifestOptions
|
29
31
|
* @property {Chunk} chunk the chunk used to render
|
30
|
-
* @property {
|
32
|
+
* @property {string} hash
|
31
33
|
* @property {string} fullHash
|
32
34
|
* @property {TODO} outputOptions
|
33
35
|
* @property {{javascript: ModuleTemplate, webassembly: ModuleTemplate}} moduleTemplates
|
@@ -92,7 +94,9 @@ module.exports = class MainTemplate extends Tapable {
|
|
92
94
|
localVars: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
93
95
|
require: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
94
96
|
requireExtensions: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
97
|
+
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
95
98
|
beforeStartup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
99
|
+
/** @type {SyncWaterfallHook<string, Chunk, string>} */
|
96
100
|
startup: new SyncWaterfallHook(["source", "chunk", "hash"]),
|
97
101
|
render: new SyncWaterfallHook([
|
98
102
|
"source",
|
@@ -361,7 +365,7 @@ module.exports = class MainTemplate extends Tapable {
|
|
361
365
|
* @param {string} hash hash to be used for render call
|
362
366
|
* @param {Chunk} chunk Chunk instance
|
363
367
|
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance for render
|
364
|
-
* @param {
|
368
|
+
* @param {Map<Function, DependencyTemplate>} dependencyTemplates dependency templates
|
365
369
|
* @returns {ConcatSource} the newly generated source from rendering
|
366
370
|
*/
|
367
371
|
render(hash, chunk, moduleTemplate, dependencyTemplates) {
|
@@ -447,7 +451,7 @@ module.exports = class MainTemplate extends Tapable {
|
|
447
451
|
/**
|
448
452
|
*
|
449
453
|
* @param {string} hash string hash
|
450
|
-
* @param {number} length length
|
454
|
+
* @param {number=} length length
|
451
455
|
* @returns {string} call hook return
|
452
456
|
*/
|
453
457
|
renderCurrentHashCode(hash, length) {
|
@@ -474,6 +478,11 @@ module.exports = class MainTemplate extends Tapable {
|
|
474
478
|
return this.hooks.assetPath.call(path, options);
|
475
479
|
}
|
476
480
|
|
481
|
+
/**
|
482
|
+
* Updates hash with information from this template
|
483
|
+
* @param {Hash} hash the hash to update
|
484
|
+
* @returns {void}
|
485
|
+
*/
|
477
486
|
updateHash(hash) {
|
478
487
|
hash.update("maintemplate");
|
479
488
|
hash.update("3");
|
@@ -481,6 +490,12 @@ module.exports = class MainTemplate extends Tapable {
|
|
481
490
|
this.hooks.hash.call(hash);
|
482
491
|
}
|
483
492
|
|
493
|
+
/**
|
494
|
+
* Updates hash with chunk-specific information from this template
|
495
|
+
* @param {Hash} hash the hash to update
|
496
|
+
* @param {Chunk} chunk the chunk
|
497
|
+
* @returns {void}
|
498
|
+
*/
|
484
499
|
updateHashForChunk(hash, chunk) {
|
485
500
|
this.updateHash(hash);
|
486
501
|
this.hooks.hashForChunk.call(hash, chunk);
|
@@ -1,5 +1,5 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
module.exports = require("memory-fs");
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
module.exports = require("memory-fs");
|
package/lib/Module.js
CHANGED
@@ -13,6 +13,7 @@ const Template = require("./Template");
|
|
13
13
|
|
14
14
|
/** @typedef {import("./Chunk")} Chunk */
|
15
15
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
16
|
+
/** @typedef {import("./WebpackError")} WebpackError */
|
16
17
|
|
17
18
|
const EMPTY_RESOLVE_OPTIONS = {};
|
18
19
|
|
@@ -47,15 +48,15 @@ class Module extends DependenciesBlock {
|
|
47
48
|
this.renderedHash = undefined;
|
48
49
|
|
49
50
|
// Info from Factory
|
50
|
-
/** @type {
|
51
|
+
/** @type {TODO} */
|
51
52
|
this.resolveOptions = EMPTY_RESOLVE_OPTIONS;
|
52
53
|
/** @type {object} */
|
53
54
|
this.factoryMeta = {};
|
54
55
|
|
55
56
|
// Info from Build
|
56
|
-
/** @type {
|
57
|
+
/** @type {WebpackError[]} */
|
57
58
|
this.warnings = [];
|
58
|
-
/** @type {
|
59
|
+
/** @type {WebpackError[]} */
|
59
60
|
this.errors = [];
|
60
61
|
/** @type {object} */
|
61
62
|
this.buildMeta = undefined;
|
@@ -181,6 +182,9 @@ class Module extends DependenciesBlock {
|
|
181
182
|
);
|
182
183
|
}
|
183
184
|
|
185
|
+
/**
|
186
|
+
* @returns {Chunk[]} all chunks which contain the module
|
187
|
+
*/
|
184
188
|
getChunks() {
|
185
189
|
return Array.from(this._chunks);
|
186
190
|
}
|
@@ -380,6 +384,8 @@ Module.prototype.build = null;
|
|
380
384
|
Module.prototype.source = null;
|
381
385
|
Module.prototype.size = null;
|
382
386
|
Module.prototype.nameForCondition = null;
|
387
|
+
/** @type {null | function(Chunk): boolean} */
|
388
|
+
Module.prototype.chunkCondition = null;
|
383
389
|
Module.prototype.updateCacheModule = null;
|
384
390
|
|
385
391
|
module.exports = Module;
|
package/lib/ModuleReason.js
CHANGED
@@ -4,7 +4,15 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
+
/** @typedef {import("./Module")} Module */
|
8
|
+
/** @typedef {import("./Dependency")} Dependency */
|
9
|
+
|
7
10
|
class ModuleReason {
|
11
|
+
/**
|
12
|
+
* @param {Module} module the referencing module
|
13
|
+
* @param {Dependency} dependency the referencing dependency
|
14
|
+
* @param {string=} explanation some extra detail
|
15
|
+
*/
|
8
16
|
constructor(module, dependency, explanation) {
|
9
17
|
this.module = module;
|
10
18
|
this.dependency = dependency;
|
package/lib/MultiEntryPlugin.js
CHANGED
@@ -8,13 +8,25 @@ const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
|
|
8
8
|
const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
|
9
9
|
const MultiModuleFactory = require("./MultiModuleFactory");
|
10
10
|
|
11
|
-
|
11
|
+
/** @typedef {import("./Compiler")} Compiler */
|
12
|
+
|
13
|
+
class MultiEntryPlugin {
|
14
|
+
/**
|
15
|
+
* The MultiEntryPlugin is invoked whenever this.options.entry value is an array of paths
|
16
|
+
* @param {string} context context path
|
17
|
+
* @param {string[]} entries array of entry paths
|
18
|
+
* @param {string} name entry key name
|
19
|
+
*/
|
12
20
|
constructor(context, entries, name) {
|
13
21
|
this.context = context;
|
14
22
|
this.entries = entries;
|
15
23
|
this.name = name;
|
16
24
|
}
|
17
25
|
|
26
|
+
/**
|
27
|
+
* @param {Compiler} compiler the compiler instance
|
28
|
+
* @returns {void}
|
29
|
+
*/
|
18
30
|
apply(compiler) {
|
19
31
|
compiler.hooks.compilation.tap(
|
20
32
|
"MultiEntryPlugin",
|
@@ -43,16 +55,26 @@ module.exports = class MultiEntryPlugin {
|
|
43
55
|
);
|
44
56
|
}
|
45
57
|
|
58
|
+
/**
|
59
|
+
* @param {string[]} entries each entry path string
|
60
|
+
* @param {string} name name of the entry
|
61
|
+
* @returns {MultiEntryDependency} returns a constructed Dependency
|
62
|
+
*/
|
46
63
|
static createDependency(entries, name) {
|
47
64
|
return new MultiEntryDependency(
|
48
65
|
entries.map((e, idx) => {
|
49
66
|
const dep = new SingleEntryDependency(e);
|
50
67
|
// Because entrypoints are not dependencies found in an
|
51
68
|
// existing module, we give it a synthetic id
|
52
|
-
dep.loc =
|
69
|
+
dep.loc = {
|
70
|
+
name,
|
71
|
+
index: idx
|
72
|
+
};
|
53
73
|
return dep;
|
54
74
|
}),
|
55
75
|
name
|
56
76
|
);
|
57
77
|
}
|
58
|
-
}
|
78
|
+
}
|
79
|
+
|
80
|
+
module.exports = MultiEntryPlugin;
|
package/lib/NormalModule.js
CHANGED
@@ -4,7 +4,6 @@
|
|
4
4
|
*/
|
5
5
|
"use strict";
|
6
6
|
|
7
|
-
const path = require("path");
|
8
7
|
const NativeModule = require("module");
|
9
8
|
|
10
9
|
const {
|
@@ -23,6 +22,7 @@ const ModuleBuildError = require("./ModuleBuildError");
|
|
23
22
|
const ModuleError = require("./ModuleError");
|
24
23
|
const ModuleWarning = require("./ModuleWarning");
|
25
24
|
const createHash = require("./util/createHash");
|
25
|
+
const contextify = require("./util/identifier").contextify;
|
26
26
|
|
27
27
|
const asString = buf => {
|
28
28
|
if (Buffer.isBuffer(buf)) {
|
@@ -38,28 +38,6 @@ const asBuffer = str => {
|
|
38
38
|
return str;
|
39
39
|
};
|
40
40
|
|
41
|
-
const contextify = (context, request) => {
|
42
|
-
return request
|
43
|
-
.split("!")
|
44
|
-
.map(r => {
|
45
|
-
const splitPath = r.split("?");
|
46
|
-
if (/^[a-zA-Z]:\\/.test(splitPath[0])) {
|
47
|
-
splitPath[0] = path.win32.relative(context, splitPath[0]);
|
48
|
-
if (!/^[a-zA-Z]:\\/.test(splitPath[0])) {
|
49
|
-
splitPath[0] = splitPath[0].replace(/\\/g, "/");
|
50
|
-
}
|
51
|
-
}
|
52
|
-
if (/^\//.test(splitPath[0])) {
|
53
|
-
splitPath[0] = path.posix.relative(context, splitPath[0]);
|
54
|
-
}
|
55
|
-
if (!/^(\.\.\/|\/|[a-zA-Z]:\\)/.test(splitPath[0])) {
|
56
|
-
splitPath[0] = "./" + splitPath[0];
|
57
|
-
}
|
58
|
-
return splitPath.join("?");
|
59
|
-
})
|
60
|
-
.join("!");
|
61
|
-
};
|
62
|
-
|
63
41
|
class NonErrorEmittedError extends WebpackError {
|
64
42
|
constructor(error) {
|
65
43
|
super();
|
@@ -191,6 +169,7 @@ class NormalModule extends Module {
|
|
191
169
|
})
|
192
170
|
);
|
193
171
|
},
|
172
|
+
// TODO remove in webpack 5
|
194
173
|
exec: (code, filename) => {
|
195
174
|
// @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
|
196
175
|
const module = new NativeModule(filename, this);
|
@@ -265,6 +244,8 @@ class NormalModule extends Module {
|
|
265
244
|
}
|
266
245
|
|
267
246
|
if (Buffer.isBuffer(source)) {
|
247
|
+
// @ts-ignore
|
248
|
+
// TODO We need to fix @types/webpack-sources to allow RawSource to take a Buffer | string
|
268
249
|
return new RawSource(source);
|
269
250
|
}
|
270
251
|
|
@@ -486,6 +467,7 @@ class NormalModule extends Module {
|
|
486
467
|
}
|
487
468
|
|
488
469
|
getHashDigest(dependencyTemplates) {
|
470
|
+
// TODO webpack 5 refactor
|
489
471
|
let dtHash = dependencyTemplates.get("hash");
|
490
472
|
return `${this.hash}-${dtHash}`;
|
491
473
|
}
|
package/lib/NullFactory.js
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
class NullFactory {
|
8
|
-
create(data, callback) {
|
9
|
-
return callback();
|
10
|
-
}
|
11
|
-
}
|
12
|
-
module.exports = NullFactory;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
class NullFactory {
|
8
|
+
create(data, callback) {
|
9
|
+
return callback();
|
10
|
+
}
|
11
|
+
}
|
12
|
+
module.exports = NullFactory;
|
package/lib/OptionsApply.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
class OptionsApply {
|
8
|
-
process(options, compiler) {}
|
9
|
-
}
|
10
|
-
module.exports = OptionsApply;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
class OptionsApply {
|
8
|
+
process(options, compiler) {}
|
9
|
+
}
|
10
|
+
module.exports = OptionsApply;
|