webpack 5.68.0 → 5.70.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/lib/BannerPlugin.js +10 -4
- package/lib/ChunkGraph.js +1 -2
- package/lib/CleanPlugin.js +64 -18
- package/lib/Compilation.js +43 -17
- package/lib/ContextModule.js +90 -26
- package/lib/ContextModuleFactory.js +65 -21
- package/lib/EntryOptionPlugin.js +1 -0
- package/lib/ExportsInfo.js +4 -4
- package/lib/Generator.js +1 -0
- package/lib/ModuleHashingError.js +29 -0
- package/lib/NodeStuffPlugin.js +10 -0
- package/lib/NormalModule.js +21 -16
- package/lib/NormalModuleFactory.js +40 -35
- package/lib/ProgressPlugin.js +4 -5
- package/lib/RuntimeTemplate.js +1 -0
- package/lib/TemplatedPathPlugin.js +48 -23
- package/lib/WebpackOptionsApply.js +2 -0
- package/lib/asset/AssetGenerator.js +122 -33
- package/lib/buildChunkGraph.js +1 -1
- package/lib/cache/ResolverCachePlugin.js +89 -28
- package/lib/config/browserslistTargetHandler.js +3 -5
- package/lib/config/defaults.js +7 -2
- package/lib/config/normalization.js +1 -0
- package/lib/css/CssLoadingRuntimeModule.js +63 -70
- package/lib/css/CssModulesPlugin.js +2 -1
- package/lib/debug/ProfilingPlugin.js +3 -4
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +8 -2
- package/lib/dependencies/ExportsInfoDependency.js +6 -0
- package/lib/dependencies/HarmonyAcceptImportDependency.js +5 -3
- package/lib/dependencies/HarmonyExportInitFragment.js +4 -1
- package/lib/dependencies/ImportContextDependency.js +0 -2
- package/lib/dependencies/ImportMetaContextDependency.js +35 -0
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +252 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +59 -0
- package/lib/dependencies/LoaderPlugin.js +2 -0
- package/lib/dependencies/RequireContextDependency.js +0 -16
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +24 -8
- package/lib/index.js +5 -0
- package/lib/javascript/JavascriptModulesPlugin.js +27 -2
- package/lib/javascript/StartupHelpers.js +3 -2
- package/lib/library/AssignLibraryPlugin.js +8 -2
- package/lib/node/NodeTargetPlugin.js +1 -0
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +22 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +22 -7
- package/lib/optimize/ConcatenatedModule.js +10 -4
- package/lib/schemes/HttpUriPlugin.js +68 -6
- package/lib/serialization/FileMiddleware.js +44 -9
- package/lib/util/compileBooleanMatcher.js +1 -1
- package/lib/util/deterministicGrouping.js +1 -1
- package/lib/util/identifier.js +65 -44
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/nonNumericOnlyHash.js +22 -0
- package/lib/util/semver.js +17 -10
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +15 -5
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +30 -20
- package/module.d.ts +15 -0
- package/package.json +13 -13
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.json +4 -0
- package/types.d.ts +203 -91
@@ -167,6 +167,9 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
167
167
|
asyncLib.parallel(
|
168
168
|
[
|
169
169
|
callback => {
|
170
|
+
const results = [];
|
171
|
+
const yield_ = obj => results.push(obj);
|
172
|
+
|
170
173
|
contextResolver.resolve(
|
171
174
|
{},
|
172
175
|
context,
|
@@ -174,11 +177,12 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
174
177
|
{
|
175
178
|
fileDependencies,
|
176
179
|
missingDependencies,
|
177
|
-
contextDependencies
|
180
|
+
contextDependencies,
|
181
|
+
yield: yield_
|
178
182
|
},
|
179
|
-
|
183
|
+
err => {
|
180
184
|
if (err) return callback(err);
|
181
|
-
callback(null,
|
185
|
+
callback(null, results);
|
182
186
|
}
|
183
187
|
);
|
184
188
|
},
|
@@ -213,15 +217,25 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
213
217
|
contextDependencies
|
214
218
|
});
|
215
219
|
}
|
216
|
-
|
220
|
+
let [contextResult, loaderResult] = result;
|
221
|
+
if (contextResult.length > 1) {
|
222
|
+
const first = contextResult[0];
|
223
|
+
contextResult = contextResult.filter(r => r.path);
|
224
|
+
if (contextResult.length === 0) contextResult.push(first);
|
225
|
+
}
|
217
226
|
this.hooks.afterResolve.callAsync(
|
218
227
|
{
|
219
228
|
addon:
|
220
229
|
loadersPrefix +
|
221
|
-
|
222
|
-
(
|
223
|
-
resource:
|
230
|
+
loaderResult.join("!") +
|
231
|
+
(loaderResult.length > 0 ? "!" : ""),
|
232
|
+
resource:
|
233
|
+
contextResult.length > 1
|
234
|
+
? contextResult.map(r => r.path)
|
235
|
+
: contextResult[0].path,
|
224
236
|
resolveDependencies: this.resolveDependencies.bind(this),
|
237
|
+
resourceQuery: contextResult[0].query,
|
238
|
+
resourceFragment: contextResult[0].fragment,
|
225
239
|
...beforeResolveResult
|
226
240
|
},
|
227
241
|
(err, result) => {
|
@@ -278,26 +292,28 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
278
292
|
} = options;
|
279
293
|
if (!regExp || !resource) return callback(null, []);
|
280
294
|
|
281
|
-
|
295
|
+
let severalContexts = false;
|
296
|
+
const addDirectoryChecked = (ctx, directory, visited, callback) => {
|
282
297
|
fs.realpath(directory, (err, realPath) => {
|
283
298
|
if (err) return callback(err);
|
284
299
|
if (visited.has(realPath)) return callback(null, []);
|
285
300
|
let recursionStack;
|
286
301
|
addDirectory(
|
302
|
+
ctx,
|
287
303
|
directory,
|
288
|
-
(dir, callback) => {
|
304
|
+
(_, dir, callback) => {
|
289
305
|
if (recursionStack === undefined) {
|
290
306
|
recursionStack = new Set(visited);
|
291
307
|
recursionStack.add(realPath);
|
292
308
|
}
|
293
|
-
addDirectoryChecked(dir, recursionStack, callback);
|
309
|
+
addDirectoryChecked(ctx, dir, recursionStack, callback);
|
294
310
|
},
|
295
311
|
callback
|
296
312
|
);
|
297
313
|
});
|
298
314
|
};
|
299
315
|
|
300
|
-
const addDirectory = (directory, addSubDirectory, callback) => {
|
316
|
+
const addDirectory = (ctx, directory, addSubDirectory, callback) => {
|
301
317
|
fs.readdir(directory, (err, files) => {
|
302
318
|
if (err) return callback(err);
|
303
319
|
const processedFiles = cmf.hooks.contextModuleFiles.call(
|
@@ -324,16 +340,15 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
324
340
|
|
325
341
|
if (stat.isDirectory()) {
|
326
342
|
if (!recursive) return callback();
|
327
|
-
addSubDirectory(subResource, callback);
|
343
|
+
addSubDirectory(ctx, subResource, callback);
|
328
344
|
} else if (
|
329
345
|
stat.isFile() &&
|
330
346
|
(!include || subResource.match(include))
|
331
347
|
) {
|
332
348
|
const obj = {
|
333
|
-
context:
|
349
|
+
context: ctx,
|
334
350
|
request:
|
335
|
-
"." +
|
336
|
-
subResource.substr(resource.length).replace(/\\/g, "/")
|
351
|
+
"." + subResource.substr(ctx.length).replace(/\\/g, "/")
|
337
352
|
};
|
338
353
|
|
339
354
|
this.hooks.alternativeRequests.callAsync(
|
@@ -344,8 +359,11 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
344
359
|
alternatives = alternatives
|
345
360
|
.filter(obj => regExp.test(obj.request))
|
346
361
|
.map(obj => {
|
362
|
+
const request = severalContexts
|
363
|
+
? join(fs, obj.context, obj.request)
|
364
|
+
: obj.request;
|
347
365
|
const dep = new ContextElementDependency(
|
348
|
-
|
366
|
+
request + resourceQuery + resourceFragment,
|
349
367
|
obj.request,
|
350
368
|
typePrefix,
|
351
369
|
category,
|
@@ -382,12 +400,38 @@ module.exports = class ContextModuleFactory extends ModuleFactory {
|
|
382
400
|
});
|
383
401
|
};
|
384
402
|
|
385
|
-
|
386
|
-
|
403
|
+
const addSubDirectory = (ctx, dir, callback) =>
|
404
|
+
addDirectory(ctx, dir, addSubDirectory, callback);
|
405
|
+
|
406
|
+
const visitResource = (resource, callback) => {
|
407
|
+
if (typeof fs.realpath === "function") {
|
408
|
+
addDirectoryChecked(resource, resource, new Set(), callback);
|
409
|
+
} else {
|
410
|
+
addDirectory(resource, resource, addSubDirectory, callback);
|
411
|
+
}
|
412
|
+
};
|
413
|
+
|
414
|
+
if (typeof resource === "string") {
|
415
|
+
visitResource(resource, callback);
|
387
416
|
} else {
|
388
|
-
|
389
|
-
|
390
|
-
|
417
|
+
severalContexts = true;
|
418
|
+
asyncLib.map(resource, visitResource, (err, result) => {
|
419
|
+
if (err) return callback(err);
|
420
|
+
|
421
|
+
// result dependencies should have unique userRequest
|
422
|
+
// ordered by resolve result
|
423
|
+
const temp = new Set();
|
424
|
+
const res = [];
|
425
|
+
for (let i = 0; i < result.length; i++) {
|
426
|
+
const inner = result[i];
|
427
|
+
for (const el of inner) {
|
428
|
+
if (temp.has(el.userRequest)) continue;
|
429
|
+
res.push(el);
|
430
|
+
temp.add(el.userRequest);
|
431
|
+
}
|
432
|
+
}
|
433
|
+
callback(null, res);
|
434
|
+
});
|
391
435
|
}
|
392
436
|
}
|
393
437
|
};
|
package/lib/EntryOptionPlugin.js
CHANGED
package/lib/ExportsInfo.js
CHANGED
@@ -291,15 +291,15 @@ class ExportsInfo {
|
|
291
291
|
}
|
292
292
|
}
|
293
293
|
for (const exportInfo of this._exports.values()) {
|
294
|
+
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
295
|
+
exportInfo.canMangleProvide = false;
|
296
|
+
changed = true;
|
297
|
+
}
|
294
298
|
if (excludeExports && excludeExports.has(exportInfo.name)) continue;
|
295
299
|
if (exportInfo.provided !== true && exportInfo.provided !== null) {
|
296
300
|
exportInfo.provided = null;
|
297
301
|
changed = true;
|
298
302
|
}
|
299
|
-
if (!canMangle && exportInfo.canMangleProvide !== false) {
|
300
|
-
exportInfo.canMangleProvide = false;
|
301
|
-
changed = true;
|
302
|
-
}
|
303
303
|
if (targetKey) {
|
304
304
|
exportInfo.setTarget(targetKey, targetModule, [exportInfo.name], -1);
|
305
305
|
}
|
package/lib/Generator.js
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const WebpackError = require("./WebpackError");
|
9
|
+
|
10
|
+
/** @typedef {import("./Module")} Module */
|
11
|
+
|
12
|
+
class ModuleHashingError extends WebpackError {
|
13
|
+
/**
|
14
|
+
* Create a new ModuleHashingError
|
15
|
+
* @param {Module} module related module
|
16
|
+
* @param {Error} error Original error
|
17
|
+
*/
|
18
|
+
constructor(module, error) {
|
19
|
+
super();
|
20
|
+
|
21
|
+
this.name = "ModuleHashingError";
|
22
|
+
this.error = error;
|
23
|
+
this.message = error.message;
|
24
|
+
this.details = error.stack;
|
25
|
+
this.module = module;
|
26
|
+
}
|
27
|
+
}
|
28
|
+
|
29
|
+
module.exports = ModuleHashingError;
|
package/lib/NodeStuffPlugin.js
CHANGED
@@ -69,6 +69,16 @@ class NodeStuffPlugin {
|
|
69
69
|
);
|
70
70
|
}
|
71
71
|
});
|
72
|
+
parser.hooks.rename.for("global").tap("NodeStuffPlugin", expr => {
|
73
|
+
const dep = new ConstDependency(
|
74
|
+
RuntimeGlobals.global,
|
75
|
+
expr.range,
|
76
|
+
[RuntimeGlobals.global]
|
77
|
+
);
|
78
|
+
dep.loc = expr.loc;
|
79
|
+
parser.state.module.addPresentationalDependency(dep);
|
80
|
+
return false;
|
81
|
+
});
|
72
82
|
}
|
73
83
|
|
74
84
|
const setModuleConstant = (expressionName, fn, warning) => {
|
package/lib/NormalModule.js
CHANGED
@@ -50,6 +50,7 @@ const memoize = require("./util/memoize");
|
|
50
50
|
/** @typedef {import("webpack-sources").Source} Source */
|
51
51
|
/** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
|
52
52
|
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
|
53
|
+
/** @typedef {import("../declarations/WebpackOptions").ResolveOptions} ResolveOptions */
|
53
54
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
54
55
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
55
56
|
/** @typedef {import("./Compiler")} Compiler */
|
@@ -194,6 +195,25 @@ makeSerializable(
|
|
194
195
|
* @property {AsyncSeriesBailHook<[NormalModule, NeedBuildContext], boolean>} needBuild
|
195
196
|
*/
|
196
197
|
|
198
|
+
/**
|
199
|
+
* @typedef {Object} NormalModuleCreateData
|
200
|
+
* @property {string=} layer an optional layer in which the module is
|
201
|
+
* @property {string} type module type
|
202
|
+
* @property {string} request request string
|
203
|
+
* @property {string} userRequest request intended by user (without loaders from config)
|
204
|
+
* @property {string} rawRequest request without resolving
|
205
|
+
* @property {LoaderItem[]} loaders list of loaders
|
206
|
+
* @property {string} resource path + query of the real resource
|
207
|
+
* @property {Record<string, any>=} resourceResolveData resource resolve data
|
208
|
+
* @property {string} context context directory for resolving
|
209
|
+
* @property {string=} matchResource path + query of the matched resource (virtual)
|
210
|
+
* @property {Parser} parser the parser used
|
211
|
+
* @property {Record<string, any>=} parserOptions the options of the parser used
|
212
|
+
* @property {Generator} generator the generator used
|
213
|
+
* @property {Record<string, any>=} generatorOptions the options of the generator used
|
214
|
+
* @property {ResolveOptions=} resolveOptions options used for resolving requests from this module
|
215
|
+
*/
|
216
|
+
|
197
217
|
/** @type {WeakMap<Compilation, NormalModuleCompilationHooks>} */
|
198
218
|
const compilationHooksMap = new WeakMap();
|
199
219
|
|
@@ -246,22 +266,7 @@ class NormalModule extends Module {
|
|
246
266
|
}
|
247
267
|
|
248
268
|
/**
|
249
|
-
* @param {
|
250
|
-
* @param {string=} options.layer an optional layer in which the module is
|
251
|
-
* @param {string} options.type module type
|
252
|
-
* @param {string} options.request request string
|
253
|
-
* @param {string} options.userRequest request intended by user (without loaders from config)
|
254
|
-
* @param {string} options.rawRequest request without resolving
|
255
|
-
* @param {LoaderItem[]} options.loaders list of loaders
|
256
|
-
* @param {string} options.resource path + query of the real resource
|
257
|
-
* @param {Record<string, any>=} options.resourceResolveData resource resolve data
|
258
|
-
* @param {string} options.context context directory for resolving
|
259
|
-
* @param {string | undefined} options.matchResource path + query of the matched resource (virtual)
|
260
|
-
* @param {Parser} options.parser the parser used
|
261
|
-
* @param {object} options.parserOptions the options of the parser used
|
262
|
-
* @param {Generator} options.generator the generator used
|
263
|
-
* @param {object} options.generatorOptions the options of the generator used
|
264
|
-
* @param {Object} options.resolveOptions options used for resolving requests from this module
|
269
|
+
* @param {NormalModuleCreateData} options options object
|
265
270
|
*/
|
266
271
|
constructor({
|
267
272
|
layer,
|
@@ -28,17 +28,25 @@ const LazySet = require("./util/LazySet");
|
|
28
28
|
const { getScheme } = require("./util/URLAbsoluteSpecifier");
|
29
29
|
const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
|
30
30
|
const { join } = require("./util/fs");
|
31
|
-
const {
|
31
|
+
const {
|
32
|
+
parseResource,
|
33
|
+
parseResourceWithoutFragment
|
34
|
+
} = require("./util/identifier");
|
32
35
|
|
33
36
|
/** @typedef {import("../declarations/WebpackOptions").ModuleOptionsNormalized} ModuleOptions */
|
37
|
+
/** @typedef {import("../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
34
38
|
/** @typedef {import("./Generator")} Generator */
|
35
39
|
/** @typedef {import("./ModuleFactory").ModuleFactoryCreateData} ModuleFactoryCreateData */
|
36
40
|
/** @typedef {import("./ModuleFactory").ModuleFactoryResult} ModuleFactoryResult */
|
41
|
+
/** @typedef {import("./NormalModule").NormalModuleCreateData} NormalModuleCreateData */
|
37
42
|
/** @typedef {import("./Parser")} Parser */
|
38
43
|
/** @typedef {import("./ResolverFactory")} ResolverFactory */
|
39
44
|
/** @typedef {import("./dependencies/ModuleDependency")} ModuleDependency */
|
40
45
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
41
46
|
|
47
|
+
/** @typedef {Pick<RuleSetRule, 'type'|'sideEffects'|'parser'|'generator'|'resolve'|'layer'>} ModuleSettings */
|
48
|
+
/** @typedef {Partial<NormalModuleCreateData & {settings: ModuleSettings}>} CreateData */
|
49
|
+
|
42
50
|
/**
|
43
51
|
* @typedef {Object} ResolveData
|
44
52
|
* @property {ModuleFactoryCreateData["contextInfo"]} contextInfo
|
@@ -48,7 +56,7 @@ const { parseResource } = require("./util/identifier");
|
|
48
56
|
* @property {Record<string, any> | undefined} assertions
|
49
57
|
* @property {ModuleDependency[]} dependencies
|
50
58
|
* @property {string} dependencyType
|
51
|
-
* @property {
|
59
|
+
* @property {CreateData} createData
|
52
60
|
* @property {LazySet<string>} fileDependencies
|
53
61
|
* @property {LazySet<string>} missingDependencies
|
54
62
|
* @property {LazySet<string>} contextDependencies
|
@@ -66,6 +74,11 @@ const { parseResource } = require("./util/identifier");
|
|
66
74
|
|
67
75
|
/** @typedef {ResourceData & { data: Record<string, any> }} ResourceDataWithData */
|
68
76
|
|
77
|
+
/** @typedef {Object} ParsedLoaderRequest
|
78
|
+
* @property {string} loader loader
|
79
|
+
* @property {string|undefined} options options
|
80
|
+
*/
|
81
|
+
|
69
82
|
const EMPTY_RESOLVE_OPTIONS = {};
|
70
83
|
const EMPTY_PARSER_OPTIONS = {};
|
71
84
|
const EMPTY_GENERATOR_OPTIONS = {};
|
@@ -97,27 +110,6 @@ const stringifyLoadersAndResource = (loaders, resource) => {
|
|
97
110
|
return str + resource;
|
98
111
|
};
|
99
112
|
|
100
|
-
/**
|
101
|
-
* @param {string} resultString resultString
|
102
|
-
* @returns {{loader: string, options: string|undefined}} parsed loader request
|
103
|
-
*/
|
104
|
-
const identToLoaderRequest = resultString => {
|
105
|
-
const idx = resultString.indexOf("?");
|
106
|
-
if (idx >= 0) {
|
107
|
-
const loader = resultString.substr(0, idx);
|
108
|
-
const options = resultString.substr(idx + 1);
|
109
|
-
return {
|
110
|
-
loader,
|
111
|
-
options
|
112
|
-
};
|
113
|
-
} else {
|
114
|
-
return {
|
115
|
-
loader: resultString,
|
116
|
-
options: undefined
|
117
|
-
};
|
118
|
-
}
|
119
|
-
};
|
120
|
-
|
121
113
|
const needCalls = (times, callback) => {
|
122
114
|
return err => {
|
123
115
|
if (--times === 0) {
|
@@ -212,7 +204,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
212
204
|
}) {
|
213
205
|
super();
|
214
206
|
this.hooks = Object.freeze({
|
215
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
207
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], Module | false | void>} */
|
216
208
|
resolve: new AsyncSeriesBailHook(["resolveData"]),
|
217
209
|
/** @type {HookMap<AsyncSeriesBailHook<[ResourceDataWithData, ResolveData], true | void>>} */
|
218
210
|
resolveForScheme: new HookMap(
|
@@ -222,15 +214,15 @@ class NormalModuleFactory extends ModuleFactory {
|
|
222
214
|
resolveInScheme: new HookMap(
|
223
215
|
() => new AsyncSeriesBailHook(["resourceData", "resolveData"])
|
224
216
|
),
|
225
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
217
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], Module>} */
|
226
218
|
factorize: new AsyncSeriesBailHook(["resolveData"]),
|
227
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
219
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
|
228
220
|
beforeResolve: new AsyncSeriesBailHook(["resolveData"]),
|
229
|
-
/** @type {AsyncSeriesBailHook<[ResolveData],
|
221
|
+
/** @type {AsyncSeriesBailHook<[ResolveData], false | void>} */
|
230
222
|
afterResolve: new AsyncSeriesBailHook(["resolveData"]),
|
231
|
-
/** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData],
|
223
|
+
/** @type {AsyncSeriesBailHook<[ResolveData["createData"], ResolveData], Module | void>} */
|
232
224
|
createModule: new AsyncSeriesBailHook(["createData", "resolveData"]),
|
233
|
-
/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData],
|
225
|
+
/** @type {SyncWaterfallHook<[Module, ResolveData["createData"], ResolveData], Module>} */
|
234
226
|
module: new SyncWaterfallHook(["module", "createData", "resolveData"]),
|
235
227
|
createParser: new HookMap(() => new SyncBailHook(["parserOptions"])),
|
236
228
|
parser: new HookMap(() => new SyncHook(["parser", "parserOptions"])),
|
@@ -264,6 +256,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|
264
256
|
const cacheParseResource = parseResource.bindCache(
|
265
257
|
associatedObjectForCache
|
266
258
|
);
|
259
|
+
const cachedParseResourceWithoutFragment =
|
260
|
+
parseResourceWithoutFragment.bindCache(associatedObjectForCache);
|
261
|
+
this._parseResourceWithoutFragment = cachedParseResourceWithoutFragment;
|
267
262
|
|
268
263
|
this.hooks.factorize.tapAsync(
|
269
264
|
{
|
@@ -311,7 +306,9 @@ class NormalModuleFactory extends ModuleFactory {
|
|
311
306
|
return callback(new Error("Empty dependency (no request)"));
|
312
307
|
}
|
313
308
|
|
314
|
-
createdModule = new NormalModule(
|
309
|
+
createdModule = new NormalModule(
|
310
|
+
/** @type {NormalModuleCreateData} */ (createData)
|
311
|
+
);
|
315
312
|
}
|
316
313
|
|
317
314
|
createdModule = this.hooks.module.call(
|
@@ -351,7 +348,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|
351
348
|
let matchResourceData = undefined;
|
352
349
|
/** @type {string} */
|
353
350
|
let unresolvedResource;
|
354
|
-
/** @type {
|
351
|
+
/** @type {ParsedLoaderRequest[]} */
|
355
352
|
let elements;
|
356
353
|
let noPreAutoLoaders = false;
|
357
354
|
let noAutoLoaders = false;
|
@@ -405,7 +402,13 @@ class NormalModuleFactory extends ModuleFactory {
|
|
405
402
|
)
|
406
403
|
.split(/!+/);
|
407
404
|
unresolvedResource = rawElements.pop();
|
408
|
-
elements = rawElements.map(
|
405
|
+
elements = rawElements.map(el => {
|
406
|
+
const { path, query } = cachedParseResourceWithoutFragment(el);
|
407
|
+
return {
|
408
|
+
loader: path,
|
409
|
+
options: query ? query.slice(1) : undefined
|
410
|
+
};
|
411
|
+
});
|
409
412
|
scheme = getScheme(unresolvedResource);
|
410
413
|
} else {
|
411
414
|
unresolvedResource = requestWithoutMatchResource;
|
@@ -1017,12 +1020,14 @@ If changing the source code is not an option there is also a resolve options cal
|
|
1017
1020
|
}
|
1018
1021
|
if (err) return callback(err);
|
1019
1022
|
|
1020
|
-
const parsedResult =
|
1023
|
+
const parsedResult = this._parseResourceWithoutFragment(result);
|
1021
1024
|
const resolved = {
|
1022
|
-
loader: parsedResult.
|
1025
|
+
loader: parsedResult.path,
|
1023
1026
|
options:
|
1024
1027
|
item.options === undefined
|
1025
|
-
? parsedResult.
|
1028
|
+
? parsedResult.query
|
1029
|
+
? parsedResult.query.slice(1)
|
1030
|
+
: undefined
|
1026
1031
|
: item.options,
|
1027
1032
|
ident: item.options === undefined ? undefined : item.ident
|
1028
1033
|
};
|
package/lib/ProgressPlugin.js
CHANGED
@@ -96,7 +96,7 @@ const createDefaultHandler = (profile, logger) => {
|
|
96
96
|
/**
|
97
97
|
* @callback ReportProgress
|
98
98
|
* @param {number} p
|
99
|
-
* @param {...string
|
99
|
+
* @param {...string} [args]
|
100
100
|
* @returns {void}
|
101
101
|
*/
|
102
102
|
|
@@ -531,15 +531,14 @@ class ProgressPlugin {
|
|
531
531
|
}
|
532
532
|
});
|
533
533
|
interceptHook(compiler.cache.hooks.endIdle, 0.01, "cache", "end idle");
|
534
|
-
compiler.hooks.
|
534
|
+
compiler.hooks.beforeRun.intercept({
|
535
535
|
name: "ProgressPlugin",
|
536
536
|
call() {
|
537
537
|
handler(0, "");
|
538
538
|
}
|
539
539
|
});
|
540
|
-
interceptHook(compiler.hooks.
|
541
|
-
interceptHook(compiler.hooks.
|
542
|
-
interceptHook(compiler.hooks.run, 0.03, "setup", "run");
|
540
|
+
interceptHook(compiler.hooks.beforeRun, 0.01, "setup", "before run");
|
541
|
+
interceptHook(compiler.hooks.run, 0.02, "setup", "run");
|
543
542
|
interceptHook(compiler.hooks.watchRun, 0.03, "setup", "watch run");
|
544
543
|
interceptHook(
|
545
544
|
compiler.hooks.normalModuleFactory,
|
package/lib/RuntimeTemplate.js
CHANGED
@@ -83,6 +83,7 @@ class RuntimeTemplate {
|
|
83
83
|
this.outputOptions = outputOptions || {};
|
84
84
|
this.requestShortener = requestShortener;
|
85
85
|
this.globalObject = getGlobalObject(outputOptions.globalObject);
|
86
|
+
this.contentHashReplacement = "X".repeat(outputOptions.hashDigestLength);
|
86
87
|
}
|
87
88
|
|
88
89
|
isIIFE() {
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const mime = require("mime-types");
|
8
9
|
const { basename, extname } = require("path");
|
9
10
|
const util = require("util");
|
10
11
|
const Chunk = require("./Chunk");
|
@@ -117,29 +118,53 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
117
118
|
// [name] - file
|
118
119
|
// [ext] - .js
|
119
120
|
if (typeof data.filename === "string") {
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
)
|
142
|
-
|
121
|
+
// check that filename is data uri
|
122
|
+
let match = data.filename.match(/^data:([^;,]+)/);
|
123
|
+
if (match) {
|
124
|
+
const ext = mime.extension(match[1]);
|
125
|
+
const emptyReplacer = replacer("", true);
|
126
|
+
|
127
|
+
replacements.set("file", emptyReplacer);
|
128
|
+
replacements.set("query", emptyReplacer);
|
129
|
+
replacements.set("fragment", emptyReplacer);
|
130
|
+
replacements.set("path", emptyReplacer);
|
131
|
+
replacements.set("base", emptyReplacer);
|
132
|
+
replacements.set("name", emptyReplacer);
|
133
|
+
replacements.set("ext", replacer(ext ? `.${ext}` : "", true));
|
134
|
+
// Legacy
|
135
|
+
replacements.set(
|
136
|
+
"filebase",
|
137
|
+
deprecated(
|
138
|
+
emptyReplacer,
|
139
|
+
"[filebase] is now [base]",
|
140
|
+
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
|
141
|
+
)
|
142
|
+
);
|
143
|
+
} else {
|
144
|
+
const { path: file, query, fragment } = parseResource(data.filename);
|
145
|
+
|
146
|
+
const ext = extname(file);
|
147
|
+
const base = basename(file);
|
148
|
+
const name = base.slice(0, base.length - ext.length);
|
149
|
+
const path = file.slice(0, file.length - base.length);
|
150
|
+
|
151
|
+
replacements.set("file", replacer(file));
|
152
|
+
replacements.set("query", replacer(query, true));
|
153
|
+
replacements.set("fragment", replacer(fragment, true));
|
154
|
+
replacements.set("path", replacer(path, true));
|
155
|
+
replacements.set("base", replacer(base));
|
156
|
+
replacements.set("name", replacer(name));
|
157
|
+
replacements.set("ext", replacer(ext, true));
|
158
|
+
// Legacy
|
159
|
+
replacements.set(
|
160
|
+
"filebase",
|
161
|
+
deprecated(
|
162
|
+
replacer(base),
|
163
|
+
"[filebase] is now [base]",
|
164
|
+
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
|
165
|
+
)
|
166
|
+
);
|
167
|
+
}
|
143
168
|
}
|
144
169
|
|
145
170
|
// Compilation context
|
@@ -35,6 +35,7 @@ const ResolverCachePlugin = require("./cache/ResolverCachePlugin");
|
|
35
35
|
|
36
36
|
const CommonJsPlugin = require("./dependencies/CommonJsPlugin");
|
37
37
|
const HarmonyModulesPlugin = require("./dependencies/HarmonyModulesPlugin");
|
38
|
+
const ImportMetaContextPlugin = require("./dependencies/ImportMetaContextPlugin");
|
38
39
|
const ImportMetaPlugin = require("./dependencies/ImportMetaPlugin");
|
39
40
|
const ImportPlugin = require("./dependencies/ImportPlugin");
|
40
41
|
const LoaderPlugin = require("./dependencies/LoaderPlugin");
|
@@ -361,6 +362,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
361
362
|
new RequireEnsurePlugin().apply(compiler);
|
362
363
|
new RequireContextPlugin().apply(compiler);
|
363
364
|
new ImportPlugin().apply(compiler);
|
365
|
+
new ImportMetaContextPlugin().apply(compiler);
|
364
366
|
new SystemPlugin().apply(compiler);
|
365
367
|
new ImportMetaPlugin().apply(compiler);
|
366
368
|
new URLPlugin().apply(compiler);
|