webpack 5.64.2 → 5.66.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/CacheFacade.js +2 -9
- package/lib/Chunk.js +2 -0
- package/lib/Compilation.js +79 -38
- package/lib/Dependency.js +10 -0
- package/lib/DependencyTemplate.js +9 -0
- package/lib/ExternalModule.js +93 -53
- package/lib/Generator.js +2 -0
- package/lib/Module.js +24 -1
- package/lib/ModuleFilenameHelpers.js +5 -1
- package/lib/NormalModule.js +3 -1
- package/lib/RuntimeGlobals.js +11 -1
- package/lib/RuntimePlugin.js +25 -0
- package/lib/RuntimeTemplate.js +113 -2
- package/lib/Template.js +2 -1
- package/lib/WatchIgnorePlugin.js +14 -1
- package/lib/Watching.js +32 -18
- package/lib/WebpackOptionsApply.js +43 -2
- package/lib/asset/AssetGenerator.js +10 -7
- package/lib/asset/RawDataUrlModule.js +145 -0
- package/lib/config/browserslistTargetHandler.js +38 -1
- package/lib/config/defaults.js +60 -4
- package/lib/config/target.js +10 -0
- package/lib/container/ContainerEntryModule.js +4 -3
- package/lib/css/CssGenerator.js +106 -0
- package/lib/css/CssLoadingRuntimeModule.js +393 -0
- package/lib/css/CssModulesPlugin.js +444 -0
- package/lib/css/CssParser.js +618 -0
- package/lib/css/walkCssTokens.js +659 -0
- package/lib/dependencies/CssExportDependency.js +85 -0
- package/lib/dependencies/CssImportDependency.js +75 -0
- package/lib/dependencies/CssLocalIdentifierDependency.js +119 -0
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +101 -0
- package/lib/dependencies/CssUrlDependency.js +132 -0
- package/lib/dependencies/URLDependency.js +3 -8
- package/lib/esm/ModuleChunkFormatPlugin.js +74 -49
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +1 -1
- package/lib/hmr/lazyCompilationBackend.js +3 -1
- package/lib/index.js +3 -0
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +2 -2
- package/lib/javascript/ChunkHelpers.js +33 -0
- package/lib/javascript/JavascriptGenerator.js +1 -0
- package/lib/javascript/JavascriptParser.js +16 -8
- package/lib/javascript/StartupHelpers.js +4 -28
- package/lib/library/AssignLibraryPlugin.js +31 -13
- package/lib/library/EnableLibraryPlugin.js +11 -0
- package/lib/node/NodeWatchFileSystem.js +85 -31
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +1 -1
- package/lib/node/RequireChunkLoadingRuntimeModule.js +1 -1
- package/lib/optimize/ConcatenatedModule.js +10 -4
- package/lib/sharing/ConsumeSharedModule.js +4 -0
- package/lib/sharing/ConsumeSharedRuntimeModule.js +25 -4
- package/lib/stats/DefaultStatsPrinterPlugin.js +1 -1
- package/lib/util/create-schema-validation.js +9 -2
- package/lib/util/extractUrlAndGlobal.js +3 -0
- package/lib/util/fs.js +10 -0
- package/lib/util/hash/xxhash64.js +2 -2
- package/lib/util/internalSerializables.js +11 -0
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +3 -3
- package/lib/webpack.js +9 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +3 -2
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +63 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.json +2 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.json +1 -0
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.json +3 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssGeneratorOptions.check.js +6 -0
- package/schemas/plugins/css/CssGeneratorOptions.json +3 -0
- package/schemas/plugins/css/CssParserOptions.check.d.ts +7 -0
- package/schemas/plugins/css/CssParserOptions.check.js +6 -0
- package/schemas/plugins/css/CssParserOptions.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/types.d.ts +147 -21
package/lib/CacheFacade.js
CHANGED
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const { forEachBail } = require("enhanced-resolve");
|
8
9
|
const asyncLib = require("neo-async");
|
9
10
|
const getLazyHashedEtag = require("./cache/getLazyHashedEtag");
|
10
11
|
const mergeEtags = require("./cache/mergeEtags");
|
@@ -46,15 +47,7 @@ class MultiItemCache {
|
|
46
47
|
* @returns {void}
|
47
48
|
*/
|
48
49
|
get(callback) {
|
49
|
-
|
50
|
-
this._items[i].get((err, result) => {
|
51
|
-
if (err) return callback(err);
|
52
|
-
if (result !== undefined) return callback(null, result);
|
53
|
-
if (++i >= this._items.length) return callback();
|
54
|
-
next(i);
|
55
|
-
});
|
56
|
-
};
|
57
|
-
next(0);
|
50
|
+
forEachBail(this._items, (item, callback) => item.get(callback), callback);
|
58
51
|
}
|
59
52
|
|
60
53
|
/**
|
package/lib/Chunk.js
CHANGED
@@ -80,6 +80,8 @@ class Chunk {
|
|
80
80
|
this.preventIntegration = false;
|
81
81
|
/** @type {(string | function(PathData, AssetInfo=): string)?} */
|
82
82
|
this.filenameTemplate = undefined;
|
83
|
+
/** @type {(string | function(PathData, AssetInfo=): string)?} */
|
84
|
+
this.cssFilenameTemplate = undefined;
|
83
85
|
/** @private @type {SortableSet<ChunkGroup>} */
|
84
86
|
this._groups = new SortableSet(undefined, compareChunkGroupsByIndex);
|
85
87
|
/** @type {RuntimeSpec} */
|
package/lib/Compilation.js
CHANGED
@@ -3193,47 +3193,87 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3193
3193
|
this;
|
3194
3194
|
const results = this.codeGenerationResults;
|
3195
3195
|
const errors = [];
|
3196
|
-
|
3197
|
-
|
3198
|
-
|
3199
|
-
|
3200
|
-
|
3201
|
-
|
3202
|
-
|
3203
|
-
|
3204
|
-
|
3205
|
-
|
3206
|
-
|
3207
|
-
|
3208
|
-
|
3209
|
-
|
3210
|
-
|
3211
|
-
|
3212
|
-
|
3213
|
-
|
3214
|
-
|
3196
|
+
/** @type {Set<Module> | undefined} */
|
3197
|
+
let notCodeGeneratedModules = undefined;
|
3198
|
+
const runIteration = () => {
|
3199
|
+
let delayedJobs = [];
|
3200
|
+
let delayedModules = new Set();
|
3201
|
+
asyncLib.eachLimit(
|
3202
|
+
jobs,
|
3203
|
+
this.options.parallelism,
|
3204
|
+
(job, callback) => {
|
3205
|
+
const { module } = job;
|
3206
|
+
const { codeGenerationDependencies } = module;
|
3207
|
+
if (codeGenerationDependencies !== undefined) {
|
3208
|
+
if (
|
3209
|
+
notCodeGeneratedModules === undefined ||
|
3210
|
+
codeGenerationDependencies.some(dep => {
|
3211
|
+
const referencedModule = moduleGraph.getModule(dep);
|
3212
|
+
return notCodeGeneratedModules.has(referencedModule);
|
3213
|
+
})
|
3214
|
+
) {
|
3215
|
+
delayedJobs.push(job);
|
3216
|
+
delayedModules.add(module);
|
3217
|
+
return callback();
|
3218
|
+
}
|
3215
3219
|
}
|
3216
|
-
|
3217
|
-
|
3218
|
-
|
3219
|
-
|
3220
|
-
|
3221
|
-
|
3222
|
-
|
3220
|
+
const { hash, runtime, runtimes } = job;
|
3221
|
+
this._codeGenerationModule(
|
3222
|
+
module,
|
3223
|
+
runtime,
|
3224
|
+
runtimes,
|
3225
|
+
hash,
|
3226
|
+
dependencyTemplates,
|
3227
|
+
chunkGraph,
|
3228
|
+
moduleGraph,
|
3229
|
+
runtimeTemplate,
|
3230
|
+
errors,
|
3231
|
+
results,
|
3232
|
+
(err, codeGenerated) => {
|
3233
|
+
if (codeGenerated) statModulesGenerated++;
|
3234
|
+
else statModulesFromCache++;
|
3235
|
+
callback(err);
|
3236
|
+
}
|
3223
3237
|
);
|
3224
|
-
|
3225
|
-
|
3238
|
+
},
|
3239
|
+
err => {
|
3240
|
+
if (err) return callback(err);
|
3241
|
+
if (delayedJobs.length > 0) {
|
3242
|
+
if (delayedJobs.length === jobs.length) {
|
3243
|
+
return callback(
|
3244
|
+
new Error(
|
3245
|
+
`Unable to make progress during code generation because of circular code generation dependency: ${Array.from(
|
3246
|
+
delayedModules,
|
3247
|
+
m => m.identifier()
|
3248
|
+
).join(", ")}`
|
3249
|
+
)
|
3250
|
+
);
|
3251
|
+
}
|
3252
|
+
jobs = delayedJobs;
|
3253
|
+
delayedJobs = [];
|
3254
|
+
notCodeGeneratedModules = delayedModules;
|
3255
|
+
delayedModules = new Set();
|
3256
|
+
return runIteration();
|
3226
3257
|
}
|
3258
|
+
if (errors.length > 0) {
|
3259
|
+
errors.sort(
|
3260
|
+
compareSelect(err => err.module, compareModulesByIdentifier)
|
3261
|
+
);
|
3262
|
+
for (const error of errors) {
|
3263
|
+
this.errors.push(error);
|
3264
|
+
}
|
3265
|
+
}
|
3266
|
+
this.logger.log(
|
3267
|
+
`${Math.round(
|
3268
|
+
(100 * statModulesGenerated) /
|
3269
|
+
(statModulesGenerated + statModulesFromCache)
|
3270
|
+
)}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
|
3271
|
+
);
|
3272
|
+
callback();
|
3227
3273
|
}
|
3228
|
-
|
3229
|
-
|
3230
|
-
|
3231
|
-
(statModulesGenerated + statModulesFromCache)
|
3232
|
-
)}% code generated (${statModulesGenerated} generated, ${statModulesFromCache} from cache)`
|
3233
|
-
);
|
3234
|
-
callback();
|
3235
|
-
}
|
3236
|
-
);
|
3274
|
+
);
|
3275
|
+
};
|
3276
|
+
runIteration();
|
3237
3277
|
}
|
3238
3278
|
|
3239
3279
|
/**
|
@@ -3283,7 +3323,8 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
|
|
3283
3323
|
moduleGraph,
|
3284
3324
|
dependencyTemplates,
|
3285
3325
|
runtimeTemplate,
|
3286
|
-
runtime
|
3326
|
+
runtime,
|
3327
|
+
codeGenerationResults: results
|
3287
3328
|
});
|
3288
3329
|
} catch (err) {
|
3289
3330
|
errors.push(new CodeGenerationError(module, err));
|
package/lib/Dependency.js
CHANGED
@@ -172,6 +172,16 @@ class Dependency {
|
|
172
172
|
this._loc = loc;
|
173
173
|
}
|
174
174
|
|
175
|
+
setLoc(startLine, startColumn, endLine, endColumn) {
|
176
|
+
this._locSL = startLine;
|
177
|
+
this._locSC = startColumn;
|
178
|
+
this._locEL = endLine;
|
179
|
+
this._locEC = endColumn;
|
180
|
+
this._locI = undefined;
|
181
|
+
this._locN = undefined;
|
182
|
+
this._loc = undefined;
|
183
|
+
}
|
184
|
+
|
175
185
|
/**
|
176
186
|
* @returns {string | null} an identifier to merge equal requests
|
177
187
|
*/
|
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
9
9
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
10
|
+
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
10
11
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
11
12
|
/** @typedef {import("./Dependency")} Dependency */
|
12
13
|
/** @typedef {import("./Dependency").RuntimeSpec} RuntimeSpec */
|
@@ -28,8 +29,16 @@
|
|
28
29
|
* @property {RuntimeSpec} runtime current runtimes, for which code is generated
|
29
30
|
* @property {InitFragment<GenerateContext>[]} initFragments mutable array of init fragments for the current module
|
30
31
|
* @property {ConcatenationScope=} concatenationScope when in a concatenated module, information about other concatenated modules
|
32
|
+
* @property {CodeGenerationResults} codeGenerationResults the code generation results
|
31
33
|
*/
|
32
34
|
|
35
|
+
/**
|
36
|
+
* @typedef {Object} CssDependencyTemplateContextExtras
|
37
|
+
* @property {Map<string, string>} cssExports the css exports
|
38
|
+
*/
|
39
|
+
|
40
|
+
/** @typedef {DependencyTemplateContext & CssDependencyTemplateContextExtras} CssDependencyTemplateContext */
|
41
|
+
|
33
42
|
class DependencyTemplate {
|
34
43
|
/* istanbul ignore next */
|
35
44
|
/**
|
package/lib/ExternalModule.js
CHANGED
@@ -53,6 +53,7 @@ const { register } = require("./util/serialization");
|
|
53
53
|
*/
|
54
54
|
|
55
55
|
const TYPES = new Set(["javascript"]);
|
56
|
+
const CSS_TYPES = new Set(["css-import"]);
|
56
57
|
const RUNTIME_REQUIREMENTS = new Set([RuntimeGlobals.module]);
|
57
58
|
const RUNTIME_REQUIREMENTS_FOR_SCRIPT = new Set([RuntimeGlobals.loadScript]);
|
58
59
|
const RUNTIME_REQUIREMENTS_FOR_MODULE = new Set([
|
@@ -392,7 +393,7 @@ class ExternalModule extends Module {
|
|
392
393
|
* @returns {Set<string>} types available (do not mutate)
|
393
394
|
*/
|
394
395
|
getSourceTypes() {
|
395
|
-
return TYPES;
|
396
|
+
return this.externalType === "css-import" ? CSS_TYPES : TYPES;
|
396
397
|
}
|
397
398
|
|
398
399
|
/**
|
@@ -409,7 +410,9 @@ class ExternalModule extends Module {
|
|
409
410
|
* @returns {boolean} true, if the chunk is ok for the module
|
410
411
|
*/
|
411
412
|
chunkCondition(chunk, { chunkGraph }) {
|
412
|
-
return
|
413
|
+
return this.externalType === "css-import"
|
414
|
+
? true
|
415
|
+
: chunkGraph.getNumberOfEntryModules(chunk) > 0;
|
413
416
|
}
|
414
417
|
|
415
418
|
/**
|
@@ -526,8 +529,14 @@ class ExternalModule extends Module {
|
|
526
529
|
return { request, externalType };
|
527
530
|
}
|
528
531
|
|
529
|
-
_getSourceData(
|
530
|
-
|
532
|
+
_getSourceData(
|
533
|
+
request,
|
534
|
+
externalType,
|
535
|
+
runtimeTemplate,
|
536
|
+
moduleGraph,
|
537
|
+
chunkGraph,
|
538
|
+
runtime
|
539
|
+
) {
|
531
540
|
switch (externalType) {
|
532
541
|
case "this":
|
533
542
|
case "window":
|
@@ -536,11 +545,12 @@ class ExternalModule extends Module {
|
|
536
545
|
case "global":
|
537
546
|
return getSourceForGlobalVariableExternal(
|
538
547
|
request,
|
539
|
-
runtimeTemplate.
|
548
|
+
runtimeTemplate.globalObject
|
540
549
|
);
|
541
550
|
case "commonjs":
|
542
551
|
case "commonjs2":
|
543
552
|
case "commonjs-module":
|
553
|
+
case "commonjs-static":
|
544
554
|
return getSourceForCommonJsExternal(request);
|
545
555
|
case "node-commonjs":
|
546
556
|
return this.buildInfo.module
|
@@ -613,60 +623,90 @@ class ExternalModule extends Module {
|
|
613
623
|
runtime,
|
614
624
|
concatenationScope
|
615
625
|
}) {
|
616
|
-
const
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
626
|
+
const { request, externalType } = this._getRequestAndExternalType();
|
627
|
+
switch (externalType) {
|
628
|
+
case "asset": {
|
629
|
+
const sources = new Map();
|
630
|
+
sources.set(
|
631
|
+
"javascript",
|
632
|
+
new RawSource(`module.exports = ${JSON.stringify(request)};`)
|
633
|
+
);
|
634
|
+
const data = new Map();
|
635
|
+
data.set("url", request);
|
636
|
+
return { sources, runtimeRequirements: RUNTIME_REQUIREMENTS, data };
|
637
|
+
}
|
638
|
+
case "css-import": {
|
639
|
+
const sources = new Map();
|
640
|
+
sources.set(
|
641
|
+
"css-import",
|
642
|
+
new RawSource(`@import url(${JSON.stringify(request)});`)
|
643
|
+
);
|
644
|
+
return {
|
645
|
+
sources,
|
646
|
+
runtimeRequirements: EMPTY_RUNTIME_REQUIREMENTS
|
647
|
+
};
|
648
|
+
}
|
649
|
+
default: {
|
650
|
+
const sourceData = this._getSourceData(
|
651
|
+
request,
|
652
|
+
externalType,
|
653
|
+
runtimeTemplate,
|
654
|
+
moduleGraph,
|
655
|
+
chunkGraph,
|
656
|
+
runtime
|
657
|
+
);
|
622
658
|
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
659
|
+
let sourceString = sourceData.expression;
|
660
|
+
if (sourceData.iife)
|
661
|
+
sourceString = `(function() { return ${sourceString}; }())`;
|
662
|
+
if (concatenationScope) {
|
663
|
+
sourceString = `${
|
664
|
+
runtimeTemplate.supportsConst() ? "const" : "var"
|
665
|
+
} ${ConcatenationScope.NAMESPACE_OBJECT_EXPORT} = ${sourceString};`;
|
666
|
+
concatenationScope.registerNamespaceExport(
|
667
|
+
ConcatenationScope.NAMESPACE_OBJECT_EXPORT
|
668
|
+
);
|
669
|
+
} else {
|
670
|
+
sourceString = `module.exports = ${sourceString};`;
|
671
|
+
}
|
672
|
+
if (sourceData.init)
|
673
|
+
sourceString = `${sourceData.init}\n${sourceString}`;
|
637
674
|
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
675
|
+
let data = undefined;
|
676
|
+
if (sourceData.chunkInitFragments) {
|
677
|
+
data = new Map();
|
678
|
+
data.set("chunkInitFragments", sourceData.chunkInitFragments);
|
679
|
+
}
|
643
680
|
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
681
|
+
const sources = new Map();
|
682
|
+
if (this.useSourceMap || this.useSimpleSourceMap) {
|
683
|
+
sources.set(
|
684
|
+
"javascript",
|
685
|
+
new OriginalSource(sourceString, this.identifier())
|
686
|
+
);
|
687
|
+
} else {
|
688
|
+
sources.set("javascript", new RawSource(sourceString));
|
689
|
+
}
|
690
|
+
|
691
|
+
let runtimeRequirements = sourceData.runtimeRequirements;
|
692
|
+
if (!concatenationScope) {
|
693
|
+
if (!runtimeRequirements) {
|
694
|
+
runtimeRequirements = RUNTIME_REQUIREMENTS;
|
695
|
+
} else {
|
696
|
+
const set = new Set(runtimeRequirements);
|
697
|
+
set.add(RuntimeGlobals.module);
|
698
|
+
runtimeRequirements = set;
|
699
|
+
}
|
700
|
+
}
|
653
701
|
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
set.add(RuntimeGlobals.module);
|
661
|
-
runtimeRequirements = set;
|
702
|
+
return {
|
703
|
+
sources,
|
704
|
+
runtimeRequirements:
|
705
|
+
runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
|
706
|
+
data
|
707
|
+
};
|
662
708
|
}
|
663
709
|
}
|
664
|
-
|
665
|
-
return {
|
666
|
-
sources,
|
667
|
-
runtimeRequirements: runtimeRequirements || EMPTY_RUNTIME_REQUIREMENTS,
|
668
|
-
data
|
669
|
-
};
|
670
710
|
}
|
671
711
|
|
672
712
|
/**
|
package/lib/Generator.js
CHANGED
@@ -7,6 +7,7 @@
|
|
7
7
|
|
8
8
|
/** @typedef {import("webpack-sources").Source} Source */
|
9
9
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
10
|
+
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
10
11
|
/** @typedef {import("./Compilation")} Compilation */
|
11
12
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
12
13
|
/** @typedef {import("./DependencyTemplate")} DependencyTemplate */
|
@@ -27,6 +28,7 @@
|
|
27
28
|
* @property {Set<string>} runtimeRequirements the requirements for runtime
|
28
29
|
* @property {RuntimeSpec} runtime the runtime
|
29
30
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
31
|
+
* @property {CodeGenerationResults=} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
30
32
|
* @property {string} type which kind of code should be generated
|
31
33
|
* @property {function(): Map<string, any>=} getData get access to the code generation data
|
32
34
|
*/
|
package/lib/Module.js
CHANGED
@@ -19,6 +19,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
19
19
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
20
20
|
/** @typedef {import("./Chunk")} Chunk */
|
21
21
|
/** @typedef {import("./ChunkGroup")} ChunkGroup */
|
22
|
+
/** @typedef {import("./CodeGenerationResults")} CodeGenerationResults */
|
22
23
|
/** @typedef {import("./Compilation")} Compilation */
|
23
24
|
/** @typedef {import("./ConcatenationScope")} ConcatenationScope */
|
24
25
|
/** @typedef {import("./Dependency")} Dependency */
|
@@ -56,6 +57,7 @@ const makeSerializable = require("./util/makeSerializable");
|
|
56
57
|
* @property {ChunkGraph} chunkGraph the chunk graph
|
57
58
|
* @property {RuntimeSpec} runtime the runtimes code should be generated for
|
58
59
|
* @property {ConcatenationScope=} concatenationScope when in concatenated module, information about other concatenated modules
|
60
|
+
* @property {CodeGenerationResults} codeGenerationResults code generation results of other modules (need to have a codeGenerationDependency to use that)
|
59
61
|
*/
|
60
62
|
|
61
63
|
/**
|
@@ -165,6 +167,8 @@ class Module extends DependenciesBlock {
|
|
165
167
|
this.buildInfo = undefined;
|
166
168
|
/** @type {Dependency[] | undefined} */
|
167
169
|
this.presentationalDependencies = undefined;
|
170
|
+
/** @type {Dependency[] | undefined} */
|
171
|
+
this.codeGenerationDependencies = undefined;
|
168
172
|
}
|
169
173
|
|
170
174
|
// TODO remove in webpack 6
|
@@ -493,6 +497,19 @@ class Module extends DependenciesBlock {
|
|
493
497
|
this.presentationalDependencies.push(presentationalDependency);
|
494
498
|
}
|
495
499
|
|
500
|
+
/**
|
501
|
+
* @param {Dependency} codeGenerationDependency dependency being tied to module.
|
502
|
+
* This is a Dependency where the code generation result of the referenced module is needed during code generation.
|
503
|
+
* The Dependency should also be added to normal dependencies via addDependency.
|
504
|
+
* @returns {void}
|
505
|
+
*/
|
506
|
+
addCodeGenerationDependency(codeGenerationDependency) {
|
507
|
+
if (this.codeGenerationDependencies === undefined) {
|
508
|
+
this.codeGenerationDependencies = [];
|
509
|
+
}
|
510
|
+
this.codeGenerationDependencies.push(codeGenerationDependency);
|
511
|
+
}
|
512
|
+
|
496
513
|
/**
|
497
514
|
* Removes all dependencies and blocks
|
498
515
|
* @returns {void}
|
@@ -501,6 +518,9 @@ class Module extends DependenciesBlock {
|
|
501
518
|
if (this.presentationalDependencies !== undefined) {
|
502
519
|
this.presentationalDependencies.length = 0;
|
503
520
|
}
|
521
|
+
if (this.codeGenerationDependencies !== undefined) {
|
522
|
+
this.codeGenerationDependencies.length = 0;
|
523
|
+
}
|
504
524
|
super.clearDependenciesAndBlocks();
|
505
525
|
}
|
506
526
|
|
@@ -799,7 +819,8 @@ class Module extends DependenciesBlock {
|
|
799
819
|
runtimeTemplate,
|
800
820
|
moduleGraph: chunkGraph.moduleGraph,
|
801
821
|
chunkGraph,
|
802
|
-
runtime: undefined
|
822
|
+
runtime: undefined,
|
823
|
+
codeGenerationResults: undefined
|
803
824
|
};
|
804
825
|
const sources = this.codeGeneration(codeGenContext).sources;
|
805
826
|
return type ? sources.get(type) : sources.get(first(this.getSourceTypes()));
|
@@ -976,6 +997,7 @@ class Module extends DependenciesBlock {
|
|
976
997
|
write(this.buildMeta);
|
977
998
|
write(this.buildInfo);
|
978
999
|
write(this.presentationalDependencies);
|
1000
|
+
write(this.codeGenerationDependencies);
|
979
1001
|
super.serialize(context);
|
980
1002
|
}
|
981
1003
|
|
@@ -993,6 +1015,7 @@ class Module extends DependenciesBlock {
|
|
993
1015
|
this.buildMeta = read();
|
994
1016
|
this.buildInfo = read();
|
995
1017
|
this.presentationalDependencies = read();
|
1018
|
+
this.codeGenerationDependencies = read();
|
996
1019
|
super.deserialize(context);
|
997
1020
|
}
|
998
1021
|
}
|
@@ -5,6 +5,7 @@
|
|
5
5
|
|
6
6
|
"use strict";
|
7
7
|
|
8
|
+
const NormalModule = require("./NormalModule");
|
8
9
|
const createHash = require("./util/createHash");
|
9
10
|
const memoize = require("./util/memoize");
|
10
11
|
|
@@ -138,7 +139,10 @@ ModuleFilenameHelpers.createFilename = (
|
|
138
139
|
);
|
139
140
|
identifier = memoize(() => requestShortener.shorten(module.identifier()));
|
140
141
|
moduleId = () => chunkGraph.getModuleId(module);
|
141
|
-
absoluteResourcePath = () =>
|
142
|
+
absoluteResourcePath = () =>
|
143
|
+
module instanceof NormalModule
|
144
|
+
? module.resource
|
145
|
+
: module.identifier().split("!").pop();
|
142
146
|
hash = getHash(identifier, hashFunction);
|
143
147
|
}
|
144
148
|
const resource = memoize(() => shortIdentifier().split("!").pop());
|
package/lib/NormalModule.js
CHANGED
@@ -1168,7 +1168,8 @@ class NormalModule extends Module {
|
|
1168
1168
|
moduleGraph,
|
1169
1169
|
chunkGraph,
|
1170
1170
|
runtime,
|
1171
|
-
concatenationScope
|
1171
|
+
concatenationScope,
|
1172
|
+
codeGenerationResults
|
1172
1173
|
}) {
|
1173
1174
|
/** @type {Set<string>} */
|
1174
1175
|
const runtimeRequirements = new Set();
|
@@ -1200,6 +1201,7 @@ class NormalModule extends Module {
|
|
1200
1201
|
runtimeRequirements,
|
1201
1202
|
runtime,
|
1202
1203
|
concatenationScope,
|
1204
|
+
codeGenerationResults,
|
1203
1205
|
getData,
|
1204
1206
|
type
|
1205
1207
|
});
|
package/lib/RuntimeGlobals.js
CHANGED
@@ -164,7 +164,7 @@ exports.scriptNonce = "__webpack_require__.nc";
|
|
164
164
|
* function to load a script tag.
|
165
165
|
* Arguments: (url: string, done: (event) => void), key?: string | number, chunkId?: string | number) => void
|
166
166
|
* done function is called when loading has finished or timeout occurred.
|
167
|
-
* It will attach to existing script tags with data-webpack == key or src == url.
|
167
|
+
* It will attach to existing script tags with data-webpack == uniqueName + ":" + key or src == url.
|
168
168
|
*/
|
169
169
|
exports.loadScript = "__webpack_require__.l";
|
170
170
|
|
@@ -190,11 +190,21 @@ exports.runtimeId = "__webpack_require__.j";
|
|
190
190
|
*/
|
191
191
|
exports.getChunkScriptFilename = "__webpack_require__.u";
|
192
192
|
|
193
|
+
/**
|
194
|
+
* the filename of the css part of the chunk
|
195
|
+
*/
|
196
|
+
exports.getChunkCssFilename = "__webpack_require__.k";
|
197
|
+
|
193
198
|
/**
|
194
199
|
* the filename of the script part of the hot update chunk
|
195
200
|
*/
|
196
201
|
exports.getChunkUpdateScriptFilename = "__webpack_require__.hu";
|
197
202
|
|
203
|
+
/**
|
204
|
+
* the filename of the css part of the hot update chunk
|
205
|
+
*/
|
206
|
+
exports.getChunkUpdateCssFilename = "__webpack_require__.hk";
|
207
|
+
|
198
208
|
/**
|
199
209
|
* startup signal from runtime
|
200
210
|
* This will be called when the runtime chunk has been loaded.
|
package/lib/RuntimePlugin.js
CHANGED
@@ -261,6 +261,31 @@ class RuntimePlugin {
|
|
261
261
|
);
|
262
262
|
return true;
|
263
263
|
});
|
264
|
+
compilation.hooks.runtimeRequirementInTree
|
265
|
+
.for(RuntimeGlobals.getChunkCssFilename)
|
266
|
+
.tap("RuntimePlugin", (chunk, set) => {
|
267
|
+
if (
|
268
|
+
typeof compilation.outputOptions.cssChunkFilename === "string" &&
|
269
|
+
/\[(full)?hash(:\d+)?\]/.test(
|
270
|
+
compilation.outputOptions.cssChunkFilename
|
271
|
+
)
|
272
|
+
) {
|
273
|
+
set.add(RuntimeGlobals.getFullHash);
|
274
|
+
}
|
275
|
+
compilation.addRuntimeModule(
|
276
|
+
chunk,
|
277
|
+
new GetChunkFilenameRuntimeModule(
|
278
|
+
"css",
|
279
|
+
"css",
|
280
|
+
RuntimeGlobals.getChunkCssFilename,
|
281
|
+
chunk =>
|
282
|
+
chunk.cssFilenameTemplate ||
|
283
|
+
compilation.outputOptions.cssChunkFilename,
|
284
|
+
false
|
285
|
+
)
|
286
|
+
);
|
287
|
+
return true;
|
288
|
+
});
|
264
289
|
compilation.hooks.runtimeRequirementInTree
|
265
290
|
.for(RuntimeGlobals.getChunkUpdateScriptFilename)
|
266
291
|
.tap("RuntimePlugin", (chunk, set) => {
|