webpack 5.48.0 → 5.49.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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/hot/only-dev-server.js +1 -1
- package/hot/poll.js +1 -1
- package/hot/signal.js +1 -1
- package/lib/Compilation.js +5 -2
- package/lib/ExternalModuleFactoryPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +4 -4
- package/lib/Module.js +1 -0
- package/lib/MultiCompiler.js +0 -2
- package/lib/NormalModule.js +38 -17
- package/lib/NormalModuleFactory.js +137 -74
- package/lib/WebpackOptionsApply.js +8 -0
- package/lib/asset/AssetModulesPlugin.js +0 -1
- package/lib/config/defaults.js +26 -5
- package/lib/config/normalization.js +6 -1
- package/lib/hmr/HotModuleReplacement.runtime.js +5 -1
- package/lib/index.js +0 -3
- package/lib/optimize/SplitChunksPlugin.js +4 -4
- package/lib/schemes/HttpUriPlugin.js +942 -25
- package/lib/serialization/BinaryMiddleware.js +0 -2
- package/package.json +1 -1
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +43 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +6 -0
- package/schemas/plugins/schemes/HttpUriPlugin.json +42 -0
- package/types.d.ts +60 -7
- package/lib/schemes/HttpsUriPlugin.js +0 -63
package/hot/only-dev-server.js
CHANGED
package/hot/poll.js
CHANGED
package/hot/signal.js
CHANGED
@@ -9,7 +9,7 @@ if (module.hot) {
|
|
9
9
|
module.hot
|
10
10
|
.check()
|
11
11
|
.then(function (updatedModules) {
|
12
|
-
if (!updatedModules
|
12
|
+
if (!updatedModules) {
|
13
13
|
if (fromUpdate) log("info", "[HMR] Update applied.");
|
14
14
|
else log("warning", "[HMR] Cannot find update.");
|
15
15
|
return;
|
package/lib/Compilation.js
CHANGED
@@ -1302,6 +1302,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1302
1302
|
|
1303
1303
|
module.needBuild(
|
1304
1304
|
{
|
1305
|
+
compilation: this,
|
1305
1306
|
fileSystemInfo: this.fileSystemInfo,
|
1306
1307
|
valueCacheVersions: this.valueCacheVersions
|
1307
1308
|
},
|
@@ -1573,10 +1574,11 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
|
|
1573
1574
|
if (err) {
|
1574
1575
|
if (dependencies.every(d => d.optional)) {
|
1575
1576
|
this.warnings.push(err);
|
1577
|
+
return callback();
|
1576
1578
|
} else {
|
1577
1579
|
this.errors.push(err);
|
1580
|
+
return callback(err);
|
1578
1581
|
}
|
1579
|
-
return callback(err);
|
1580
1582
|
}
|
1581
1583
|
|
1582
1584
|
if (!newModule) {
|
@@ -3784,8 +3786,9 @@ This prevents using hashes of each other and should be avoided.`);
|
|
3784
3786
|
/** @type {Map<string, {hash: string, source: Source, chunk: Chunk}>} */
|
3785
3787
|
const alreadyWrittenFiles = new Map();
|
3786
3788
|
|
3787
|
-
asyncLib.
|
3789
|
+
asyncLib.forEachLimit(
|
3788
3790
|
this.chunks,
|
3791
|
+
15,
|
3789
3792
|
(chunk, callback) => {
|
3790
3793
|
/** @type {RenderManifestEntry[]} */
|
3791
3794
|
let manifest;
|
@@ -62,6 +62,7 @@ class ExternalModuleFactoryPlugin {
|
|
62
62
|
const context = data.context;
|
63
63
|
const contextInfo = data.contextInfo;
|
64
64
|
const dependency = data.dependencies[0];
|
65
|
+
const dependencyType = data.dependencyType;
|
65
66
|
|
66
67
|
/**
|
67
68
|
* @param {string|string[]|boolean|Record<string, string|string[]>} value the external config
|
@@ -172,7 +173,6 @@ class ExternalModuleFactoryPlugin {
|
|
172
173
|
cb
|
173
174
|
);
|
174
175
|
} else {
|
175
|
-
const dependencyType = dependency.category || "";
|
176
176
|
const promise = externals(
|
177
177
|
{
|
178
178
|
context,
|
@@ -297,10 +297,10 @@ class HotModuleReplacementPlugin {
|
|
297
297
|
records.hotIndex = hotIndex;
|
298
298
|
records.fullHashChunkModuleHashes = fullHashChunkModuleHashes;
|
299
299
|
records.chunkModuleHashes = chunkModuleHashes;
|
300
|
-
records.
|
300
|
+
records.chunkHashes = {};
|
301
301
|
records.chunkRuntime = {};
|
302
302
|
for (const chunk of compilation.chunks) {
|
303
|
-
records.
|
303
|
+
records.chunkHashes[chunk.id] = chunk.hash;
|
304
304
|
records.chunkRuntime[chunk.id] = getRuntimeKey(chunk.runtime);
|
305
305
|
}
|
306
306
|
records.chunkModuleIds = {};
|
@@ -420,7 +420,7 @@ class HotModuleReplacementPlugin {
|
|
420
420
|
if (records.hash === compilation.hash) return;
|
421
421
|
if (
|
422
422
|
!records.chunkModuleHashes ||
|
423
|
-
!records.
|
423
|
+
!records.chunkHashes ||
|
424
424
|
!records.chunkModuleIds
|
425
425
|
) {
|
426
426
|
return;
|
@@ -477,7 +477,7 @@ class HotModuleReplacementPlugin {
|
|
477
477
|
/** @type {Set<string | number>} */
|
478
478
|
const completelyRemovedModules = new Set();
|
479
479
|
|
480
|
-
for (const key of Object.keys(records.
|
480
|
+
for (const key of Object.keys(records.chunkHashes)) {
|
481
481
|
const oldRuntime = keyToRuntime(records.chunkRuntime[key]);
|
482
482
|
/** @type {Module[]} */
|
483
483
|
const remainingModules = [];
|
package/lib/Module.js
CHANGED
@@ -93,6 +93,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
93
93
|
|
94
94
|
/**
|
95
95
|
* @typedef {Object} NeedBuildContext
|
96
|
+
* @property {Compilation} compilation
|
96
97
|
* @property {FileSystemInfo} fileSystemInfo
|
97
98
|
* @property {Map<string, string | Set<string>>} valueCacheVersions
|
98
99
|
*/
|
package/lib/MultiCompiler.js
CHANGED
@@ -87,7 +87,6 @@ module.exports = class MultiCompiler {
|
|
87
87
|
const compiler = this.compilers[index];
|
88
88
|
const compilerIndex = index;
|
89
89
|
let compilerDone = false;
|
90
|
-
// eslint-disable-next-line no-loop-func
|
91
90
|
compiler.hooks.done.tap("MultiCompiler", stats => {
|
92
91
|
if (!compilerDone) {
|
93
92
|
compilerDone = true;
|
@@ -98,7 +97,6 @@ module.exports = class MultiCompiler {
|
|
98
97
|
this.hooks.done.call(new MultiStats(compilerStats));
|
99
98
|
}
|
100
99
|
});
|
101
|
-
// eslint-disable-next-line no-loop-func
|
102
100
|
compiler.hooks.invalid.tap("MultiCompiler", () => {
|
103
101
|
if (compilerDone) {
|
104
102
|
compilerDone = false;
|
package/lib/NormalModule.js
CHANGED
@@ -16,6 +16,7 @@ const {
|
|
16
16
|
SourceMapSource
|
17
17
|
} = require("webpack-sources");
|
18
18
|
const Compilation = require("./Compilation");
|
19
|
+
const HookWebpackError = require("./HookWebpackError");
|
19
20
|
const Module = require("./Module");
|
20
21
|
const ModuleBuildError = require("./ModuleBuildError");
|
21
22
|
const ModuleError = require("./ModuleError");
|
@@ -178,6 +179,7 @@ makeSerializable(
|
|
178
179
|
* @property {SyncHook<[object, NormalModule]>} loader
|
179
180
|
* @property {SyncHook<[LoaderItem[], NormalModule, object]>} beforeLoaders
|
180
181
|
* @property {HookMap<AsyncSeriesBailHook<[string, NormalModule], string | Buffer>>} readResourceForScheme
|
182
|
+
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
181
183
|
*/
|
182
184
|
|
183
185
|
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
|
@@ -201,7 +203,8 @@ class NormalModule extends Module {
|
|
201
203
|
beforeLoaders: new SyncHook(["loaders", "module", "loaderContext"]),
|
202
204
|
readResourceForScheme: new HookMap(
|
203
205
|
() => new AsyncSeriesBailHook(["resource", "module"])
|
204
|
-
)
|
206
|
+
),
|
207
|
+
needBuild: new AsyncSeriesBailHook(["module", "context"])
|
205
208
|
};
|
206
209
|
compilationHooksMap.set(compilation, hooks);
|
207
210
|
}
|
@@ -218,6 +221,7 @@ class NormalModule extends Module {
|
|
218
221
|
* @param {LoaderItem[]} options.loaders list of loaders
|
219
222
|
* @param {string} options.resource path + query of the real resource
|
220
223
|
* @param {Record<string, any>=} options.resourceResolveData resource resolve data
|
224
|
+
* @param {string} options.context context directory for resolving
|
221
225
|
* @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
|
222
226
|
* @param {Parser} options.parser the parser used
|
223
227
|
* @param {object} options.parserOptions the options of the parser used
|
@@ -234,6 +238,7 @@ class NormalModule extends Module {
|
|
234
238
|
loaders,
|
235
239
|
resource,
|
236
240
|
resourceResolveData,
|
241
|
+
context,
|
237
242
|
matchResource,
|
238
243
|
parser,
|
239
244
|
parserOptions,
|
@@ -241,7 +246,7 @@ class NormalModule extends Module {
|
|
241
246
|
generatorOptions,
|
242
247
|
resolveOptions
|
243
248
|
}) {
|
244
|
-
super(type, getContext(resource), layer);
|
249
|
+
super(type, context || getContext(resource), layer);
|
245
250
|
|
246
251
|
// Info from Factory
|
247
252
|
/** @type {string} */
|
@@ -352,6 +357,7 @@ class NormalModule extends Module {
|
|
352
357
|
this.generator = m.generator;
|
353
358
|
this.generatorOptions = m.generatorOptions;
|
354
359
|
this.resource = m.resource;
|
360
|
+
this.context = m.context;
|
355
361
|
this.matchResource = m.matchResource;
|
356
362
|
this.loaders = m.loaders;
|
357
363
|
}
|
@@ -751,6 +757,13 @@ class NormalModule extends Module {
|
|
751
757
|
|
752
758
|
const hooks = NormalModule.getCompilationHooks(compilation);
|
753
759
|
|
760
|
+
this.buildInfo.fileDependencies = new LazySet();
|
761
|
+
this.buildInfo.contextDependencies = new LazySet();
|
762
|
+
this.buildInfo.missingDependencies = new LazySet();
|
763
|
+
if (this.loaders.length > 0) {
|
764
|
+
this.buildInfo.buildDependencies = new LazySet();
|
765
|
+
}
|
766
|
+
this.buildInfo.cacheable = true;
|
754
767
|
try {
|
755
768
|
hooks.beforeLoaders.call(this.loaders, this, loaderContext);
|
756
769
|
} catch (err) {
|
@@ -762,7 +775,8 @@ class NormalModule extends Module {
|
|
762
775
|
resource: this.resource,
|
763
776
|
loaders: this.loaders,
|
764
777
|
context: loaderContext,
|
765
|
-
processResource: (loaderContext,
|
778
|
+
processResource: (loaderContext, resourcePath, callback) => {
|
779
|
+
const resource = loaderContext.resource;
|
766
780
|
const scheme = getScheme(resource);
|
767
781
|
if (scheme) {
|
768
782
|
hooks.readResourceForScheme
|
@@ -775,8 +789,8 @@ class NormalModule extends Module {
|
|
775
789
|
return callback(null, result);
|
776
790
|
});
|
777
791
|
} else {
|
778
|
-
loaderContext.addDependency(
|
779
|
-
fs.readFile(
|
792
|
+
loaderContext.addDependency(resourcePath);
|
793
|
+
fs.readFile(resourcePath, callback);
|
780
794
|
}
|
781
795
|
}
|
782
796
|
},
|
@@ -789,27 +803,19 @@ class NormalModule extends Module {
|
|
789
803
|
undefined;
|
790
804
|
|
791
805
|
if (!result) {
|
806
|
+
this.buildInfo.cacheable = false;
|
792
807
|
return processResult(
|
793
808
|
err || new Error("No result from loader-runner processing"),
|
794
809
|
null
|
795
810
|
);
|
796
811
|
}
|
797
|
-
this.buildInfo.fileDependencies = new LazySet();
|
798
812
|
this.buildInfo.fileDependencies.addAll(result.fileDependencies);
|
799
|
-
this.buildInfo.contextDependencies = new LazySet();
|
800
813
|
this.buildInfo.contextDependencies.addAll(result.contextDependencies);
|
801
|
-
this.buildInfo.missingDependencies = new LazySet();
|
802
814
|
this.buildInfo.missingDependencies.addAll(result.missingDependencies);
|
803
|
-
if (
|
804
|
-
this.loaders.length > 0 &&
|
805
|
-
this.buildInfo.buildDependencies === undefined
|
806
|
-
) {
|
807
|
-
this.buildInfo.buildDependencies = new LazySet();
|
808
|
-
}
|
809
815
|
for (const loader of this.loaders) {
|
810
816
|
this.buildInfo.buildDependencies.add(loader.loader);
|
811
817
|
}
|
812
|
-
this.buildInfo.cacheable = result.cacheable;
|
818
|
+
this.buildInfo.cacheable = this.buildInfo.cacheable && result.cacheable;
|
813
819
|
processResult(err, result.result);
|
814
820
|
}
|
815
821
|
);
|
@@ -1178,7 +1184,8 @@ class NormalModule extends Module {
|
|
1178
1184
|
* @param {function(WebpackError=, boolean=): void} callback callback function, returns true, if the module needs a rebuild
|
1179
1185
|
* @returns {void}
|
1180
1186
|
*/
|
1181
|
-
needBuild(
|
1187
|
+
needBuild(context, callback) {
|
1188
|
+
const { fileSystemInfo, compilation, valueCacheVersions } = context;
|
1182
1189
|
// build if enforced
|
1183
1190
|
if (this._forceBuild) return callback(null, true);
|
1184
1191
|
|
@@ -1213,7 +1220,20 @@ class NormalModule extends Module {
|
|
1213
1220
|
|
1214
1221
|
// check snapshot for validity
|
1215
1222
|
fileSystemInfo.checkSnapshotValid(this.buildInfo.snapshot, (err, valid) => {
|
1216
|
-
callback(err
|
1223
|
+
if (err) return callback(err);
|
1224
|
+
if (!valid) return callback(null, true);
|
1225
|
+
const hooks = NormalModule.getCompilationHooks(compilation);
|
1226
|
+
hooks.needBuild.callAsync(this, context, (err, needBuild) => {
|
1227
|
+
if (err) {
|
1228
|
+
return callback(
|
1229
|
+
HookWebpackError.makeWebpackError(
|
1230
|
+
err,
|
1231
|
+
"NormalModule.getCompilationHooks().needBuild"
|
1232
|
+
)
|
1233
|
+
);
|
1234
|
+
}
|
1235
|
+
callback(null, !!needBuild);
|
1236
|
+
});
|
1217
1237
|
});
|
1218
1238
|
}
|
1219
1239
|
|
@@ -1298,6 +1318,7 @@ class NormalModule extends Module {
|
|
1298
1318
|
type: "",
|
1299
1319
|
// will be filled by updateCacheModule
|
1300
1320
|
resource: "",
|
1321
|
+
context: "",
|
1301
1322
|
request: null,
|
1302
1323
|
userRequest: null,
|
1303
1324
|
rawRequest: null,
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { getContext } = require("loader-runner");
|
8
9
|
const asyncLib = require("neo-async");
|
9
10
|
const {
|
10
11
|
AsyncSeriesBailHook,
|
@@ -46,6 +47,7 @@ const { parseResource } = require("./util/identifier");
|
|
46
47
|
* @property {string} request
|
47
48
|
* @property {Record<string, any> | undefined} assertions
|
48
49
|
* @property {ModuleDependency[]} dependencies
|
50
|
+
* @property {string} dependencyType
|
49
51
|
* @property {Object} createData
|
50
52
|
* @property {LazySet<string>} fileDependencies
|
51
53
|
* @property {LazySet<string>} missingDependencies
|
@@ -59,6 +61,7 @@ const { parseResource } = require("./util/identifier");
|
|
59
61
|
* @property {string} path
|
60
62
|
* @property {string} query
|
61
63
|
* @property {string} fragment
|
64
|
+
* @property {string=} context
|
62
65
|
*/
|
63
66
|
|
64
67
|
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
|
@@ -66,6 +69,7 @@ const { parseResource } = require("./util/identifier");
|
|
66
69
|
const EMPTY_RESOLVE_OPTIONS = {};
|
67
70
|
const EMPTY_PARSER_OPTIONS = {};
|
68
71
|
const EMPTY_GENERATOR_OPTIONS = {};
|
72
|
+
const EMPTY_ELEMENTS = [];
|
69
73
|
|
70
74
|
const MATCH_RESOURCE_REGEX = /^([^!]+)!=!/;
|
71
75
|
|
@@ -220,6 +224,10 @@ class NormalModuleFactory extends ModuleFactory {
|
|
220
224
|
resolveForScheme: new HookMap(
|
221
225
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
222
226
|
),
|
227
|
+
/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
|
228
|
+
resolveInScheme: new HookMap(
|
229
|
+
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
230
|
+
),
|
223
231
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
224
232
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
225
233
|
/** @type {AsyncSeriesBailHook<[ResolveData], TODO>} */
|
@@ -340,6 +348,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
340
348
|
contextInfo,
|
341
349
|
context,
|
342
350
|
dependencies,
|
351
|
+
dependencyType,
|
343
352
|
request,
|
344
353
|
assertions,
|
345
354
|
resolveOptions,
|
@@ -347,49 +356,76 @@ class NormalModuleFactory extends ModuleFactory {
|
|
347
356
|
missingDependencies,
|
348
357
|
contextDependencies
|
349
358
|
} = data;
|
350
|
-
const dependencyType =
|
351
|
-
(dependencies.length > 0 && dependencies[0].category) || "";
|
352
359
|
const loaderResolver = this.getResolver("loader");
|
353
360
|
|
354
361
|
/** @type {ResourceData | undefined} */
|
355
362
|
let matchResourceData = undefined;
|
356
363
|
/** @type {string} */
|
357
|
-
let
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
364
|
+
let unresolvedResource;
|
365
|
+
/** @type {{loader: string, options: string|undefined}[]} */
|
366
|
+
let elements;
|
367
|
+
let noPreAutoLoaders = false;
|
368
|
+
let noAutoLoaders = false;
|
369
|
+
let noPrePostAutoLoaders = false;
|
370
|
+
|
371
|
+
const contextScheme = getScheme(context);
|
372
|
+
/** @type {string | undefined} */
|
373
|
+
let scheme = getScheme(request);
|
374
|
+
|
375
|
+
if (!scheme) {
|
376
|
+
/** @type {string} */
|
377
|
+
let requestWithoutMatchResource = request;
|
378
|
+
const matchResourceMatch = MATCH_RESOURCE_REGEX.exec(request);
|
379
|
+
if (matchResourceMatch) {
|
380
|
+
let matchResource = matchResourceMatch[1];
|
381
|
+
if (matchResource.charCodeAt(0) === 46) {
|
382
|
+
// 46 === ".", 47 === "/"
|
383
|
+
const secondChar = matchResource.charCodeAt(1);
|
384
|
+
if (
|
385
|
+
secondChar === 47 ||
|
386
|
+
(secondChar === 46 && matchResource.charCodeAt(2) === 47)
|
387
|
+
) {
|
388
|
+
// if matchResources startsWith ../ or ./
|
389
|
+
matchResource = join(this.fs, context, matchResource);
|
390
|
+
}
|
370
391
|
}
|
392
|
+
matchResourceData = {
|
393
|
+
resource: matchResource,
|
394
|
+
...cacheParseResource(matchResource)
|
395
|
+
};
|
396
|
+
requestWithoutMatchResource = request.substr(
|
397
|
+
matchResourceMatch[0].length
|
398
|
+
);
|
371
399
|
}
|
372
|
-
matchResourceData = {
|
373
|
-
resource: matchResource,
|
374
|
-
...cacheParseResource(matchResource)
|
375
|
-
};
|
376
|
-
requestWithoutMatchResource = request.substr(
|
377
|
-
matchResourceMatch[0].length
|
378
|
-
);
|
379
|
-
}
|
380
400
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
401
|
+
scheme = getScheme(requestWithoutMatchResource);
|
402
|
+
|
403
|
+
if (!scheme && !contextScheme) {
|
404
|
+
const firstChar = requestWithoutMatchResource.charCodeAt(0);
|
405
|
+
const secondChar = requestWithoutMatchResource.charCodeAt(1);
|
406
|
+
noPreAutoLoaders = firstChar === 45 && secondChar === 33; // startsWith "-!"
|
407
|
+
noAutoLoaders = noPreAutoLoaders || firstChar === 33; // startsWith "!"
|
408
|
+
noPrePostAutoLoaders = firstChar === 33 && secondChar === 33; // startsWith "!!";
|
409
|
+
const rawElements = requestWithoutMatchResource
|
410
|
+
.slice(
|
411
|
+
noPreAutoLoaders || noPrePostAutoLoaders
|
412
|
+
? 2
|
413
|
+
: noAutoLoaders
|
414
|
+
? 1
|
415
|
+
: 0
|
416
|
+
)
|
417
|
+
.split(/!+/);
|
418
|
+
unresolvedResource = rawElements.pop();
|
419
|
+
elements = rawElements.map(identToLoaderRequest);
|
420
|
+
scheme = getScheme(unresolvedResource);
|
421
|
+
} else {
|
422
|
+
unresolvedResource = requestWithoutMatchResource;
|
423
|
+
elements = EMPTY_ELEMENTS;
|
424
|
+
}
|
425
|
+
} else {
|
426
|
+
unresolvedResource = request;
|
427
|
+
elements = EMPTY_ELEMENTS;
|
428
|
+
}
|
393
429
|
|
394
430
|
const resolveContext = {
|
395
431
|
fileDependencies,
|
@@ -399,8 +435,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|
399
435
|
|
400
436
|
/** @type {ResourceDataWithData} */
|
401
437
|
let resourceData;
|
402
|
-
/** @type {string | undefined} */
|
403
|
-
const scheme = getScheme(unresolvedResource);
|
404
438
|
|
405
439
|
let loaders;
|
406
440
|
|
@@ -540,6 +574,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
540
574
|
rawRequest: request,
|
541
575
|
loaders: allLoaders,
|
542
576
|
resource: resourceData.resource,
|
577
|
+
context:
|
578
|
+
resourceData.context || getContext(resourceData.resource),
|
543
579
|
matchResource: matchResourceData
|
544
580
|
? matchResourceData.resource
|
545
581
|
: undefined,
|
@@ -594,7 +630,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
594
630
|
|
595
631
|
this.resolveRequestArray(
|
596
632
|
contextInfo,
|
597
|
-
context,
|
633
|
+
contextScheme ? this.context : context,
|
598
634
|
elements,
|
599
635
|
loaderResolver,
|
600
636
|
resolveContext,
|
@@ -605,6 +641,49 @@ class NormalModuleFactory extends ModuleFactory {
|
|
605
641
|
}
|
606
642
|
);
|
607
643
|
|
644
|
+
const defaultResolve = context => {
|
645
|
+
if (/^($|\?)/.test(unresolvedResource)) {
|
646
|
+
resourceData = {
|
647
|
+
resource: unresolvedResource,
|
648
|
+
data: {},
|
649
|
+
...cacheParseResource(unresolvedResource)
|
650
|
+
};
|
651
|
+
continueCallback();
|
652
|
+
}
|
653
|
+
|
654
|
+
// resource without scheme and with path
|
655
|
+
else {
|
656
|
+
const normalResolver = this.getResolver(
|
657
|
+
"normal",
|
658
|
+
dependencyType
|
659
|
+
? cachedSetProperty(
|
660
|
+
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
661
|
+
"dependencyType",
|
662
|
+
dependencyType
|
663
|
+
)
|
664
|
+
: resolveOptions
|
665
|
+
);
|
666
|
+
this.resolveResource(
|
667
|
+
contextInfo,
|
668
|
+
context,
|
669
|
+
unresolvedResource,
|
670
|
+
normalResolver,
|
671
|
+
resolveContext,
|
672
|
+
(err, resolvedResource, resolvedResourceResolveData) => {
|
673
|
+
if (err) return continueCallback(err);
|
674
|
+
if (resolvedResource !== false) {
|
675
|
+
resourceData = {
|
676
|
+
resource: resolvedResource,
|
677
|
+
data: resolvedResourceResolveData,
|
678
|
+
...cacheParseResource(resolvedResource)
|
679
|
+
};
|
680
|
+
}
|
681
|
+
continueCallback();
|
682
|
+
}
|
683
|
+
);
|
684
|
+
}
|
685
|
+
};
|
686
|
+
|
608
687
|
// resource with scheme
|
609
688
|
if (scheme) {
|
610
689
|
resourceData = {
|
@@ -612,7 +691,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
612
691
|
data: {},
|
613
692
|
path: undefined,
|
614
693
|
query: undefined,
|
615
|
-
fragment: undefined
|
694
|
+
fragment: undefined,
|
695
|
+
context: undefined
|
616
696
|
};
|
617
697
|
this.hooks.resolveForScheme
|
618
698
|
.for(scheme)
|
@@ -622,47 +702,27 @@ class NormalModuleFactory extends ModuleFactory {
|
|
622
702
|
});
|
623
703
|
}
|
624
704
|
|
625
|
-
// resource
|
626
|
-
else if (
|
705
|
+
// resource within scheme
|
706
|
+
else if (contextScheme) {
|
627
707
|
resourceData = {
|
628
708
|
resource: unresolvedResource,
|
629
709
|
data: {},
|
630
|
-
|
710
|
+
path: undefined,
|
711
|
+
query: undefined,
|
712
|
+
fragment: undefined,
|
713
|
+
context: undefined
|
631
714
|
};
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
// resource without scheme and with path
|
636
|
-
else {
|
637
|
-
const normalResolver = this.getResolver(
|
638
|
-
"normal",
|
639
|
-
dependencyType
|
640
|
-
? cachedSetProperty(
|
641
|
-
resolveOptions || EMPTY_RESOLVE_OPTIONS,
|
642
|
-
"dependencyType",
|
643
|
-
dependencyType
|
644
|
-
)
|
645
|
-
: resolveOptions
|
646
|
-
);
|
647
|
-
this.resolveResource(
|
648
|
-
contextInfo,
|
649
|
-
context,
|
650
|
-
unresolvedResource,
|
651
|
-
normalResolver,
|
652
|
-
resolveContext,
|
653
|
-
(err, resolvedResource, resolvedResourceResolveData) => {
|
715
|
+
this.hooks.resolveInScheme
|
716
|
+
.for(contextScheme)
|
717
|
+
.callAsync(resourceData, data, (err, handled) => {
|
654
718
|
if (err) return continueCallback(err);
|
655
|
-
if (
|
656
|
-
resourceData = {
|
657
|
-
resource: resolvedResource,
|
658
|
-
data: resolvedResourceResolveData,
|
659
|
-
...cacheParseResource(resolvedResource)
|
660
|
-
};
|
661
|
-
}
|
719
|
+
if (!handled) return defaultResolve(this.context);
|
662
720
|
continueCallback();
|
663
|
-
}
|
664
|
-
);
|
721
|
+
});
|
665
722
|
}
|
723
|
+
|
724
|
+
// resource without scheme and without path
|
725
|
+
else defaultResolve(context);
|
666
726
|
}
|
667
727
|
);
|
668
728
|
}
|
@@ -703,6 +763,8 @@ class NormalModuleFactory extends ModuleFactory {
|
|
703
763
|
const fileDependencies = new LazySet();
|
704
764
|
const missingDependencies = new LazySet();
|
705
765
|
const contextDependencies = new LazySet();
|
766
|
+
const dependencyType =
|
767
|
+
(dependencies.length > 0 && dependencies[0].category) || "";
|
706
768
|
/** @type {ResolveData} */
|
707
769
|
const resolveData = {
|
708
770
|
contextInfo,
|
@@ -711,6 +773,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
711
773
|
request,
|
712
774
|
assertions,
|
713
775
|
dependencies,
|
776
|
+
dependencyType,
|
714
777
|
fileDependencies,
|
715
778
|
missingDependencies,
|
716
779
|
contextDependencies,
|
@@ -857,7 +920,7 @@ ${hints.join("\n\n")}`;
|
|
857
920
|
null,
|
858
921
|
`Did you mean '${resource}'?
|
859
922
|
BREAKING CHANGE: The request '${unresolvedResource}' failed to resolve only because it was resolved as fully specified
|
860
|
-
(probably because the origin is a '*.mjs' file or a '*.js' file where the package.json contains '"type": "module"').
|
923
|
+
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
|
861
924
|
The extension in the request is mandatory for it to be fully specified.
|
862
925
|
Add the extension to the request.`
|
863
926
|
);
|
@@ -276,6 +276,14 @@ class WebpackOptionsApply extends OptionsApply {
|
|
276
276
|
}).apply(compiler);
|
277
277
|
}
|
278
278
|
|
279
|
+
if (options.experiments.buildHttp) {
|
280
|
+
const HttpUriPlugin = require("./schemes/HttpUriPlugin");
|
281
|
+
const httpOptions = options.experiments.buildHttp;
|
282
|
+
if (httpOptions === true)
|
283
|
+
throw new Error("Unexpected due to normalization");
|
284
|
+
new HttpUriPlugin(httpOptions).apply(compiler);
|
285
|
+
}
|
286
|
+
|
279
287
|
new EntryOptionPlugin().apply(compiler);
|
280
288
|
compiler.hooks.entryOption.call(options.context, options.entry);
|
281
289
|
|
@@ -120,7 +120,6 @@ class AssetModulesPlugin {
|
|
120
120
|
for (const type of ["asset", "asset/inline", "asset/resource"]) {
|
121
121
|
normalModuleFactory.hooks.createGenerator
|
122
122
|
.for(type)
|
123
|
-
// eslint-disable-next-line no-loop-func
|
124
123
|
.tap(plugin, generatorOptions => {
|
125
124
|
validateGeneratorOptions[type](generatorOptions);
|
126
125
|
|