webpack 5.95.0 → 5.96.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/README.md +1 -1
- package/lib/AsyncDependenciesBlock.js +1 -1
- package/lib/BannerPlugin.js +2 -1
- package/lib/Chunk.js +30 -0
- package/lib/ChunkGraph.js +11 -6
- package/lib/ChunkGroup.js +2 -2
- package/lib/CleanPlugin.js +4 -5
- package/lib/CodeGenerationResults.js +6 -5
- package/lib/Compilation.js +71 -48
- package/lib/Compiler.js +7 -5
- package/lib/ConcatenationScope.js +7 -20
- package/lib/ContextModule.js +7 -8
- package/lib/CssModule.js +25 -21
- package/lib/DefinePlugin.js +14 -8
- package/lib/DelegatedModule.js +3 -3
- package/lib/DllModule.js +4 -4
- package/lib/DynamicEntryPlugin.js +29 -22
- package/lib/EvalDevToolModulePlugin.js +5 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -2
- package/lib/ExternalModule.js +40 -7
- package/lib/ExternalModuleFactoryPlugin.js +33 -9
- package/lib/FileSystemInfo.js +12 -8
- package/lib/Generator.js +5 -4
- package/lib/HotModuleReplacementPlugin.js +8 -6
- package/lib/IgnorePlugin.js +19 -1
- package/lib/LoaderOptionsPlugin.js +3 -1
- package/lib/Module.js +9 -8
- package/lib/ModuleSourceTypesConstants.js +100 -0
- package/lib/NormalModule.js +27 -17
- package/lib/NormalModuleFactory.js +38 -22
- package/lib/OptionsApply.js +12 -1
- package/lib/ProgressPlugin.js +50 -10
- package/lib/RawModule.js +3 -4
- package/lib/RuntimeModule.js +3 -4
- package/lib/RuntimePlugin.js +11 -4
- package/lib/RuntimeTemplate.js +13 -42
- package/lib/SourceMapDevToolPlugin.js +10 -7
- package/lib/Watching.js +2 -2
- package/lib/WebpackOptionsApply.js +42 -21
- package/lib/asset/AssetGenerator.js +347 -194
- package/lib/asset/AssetModulesPlugin.js +2 -1
- package/lib/asset/AssetSourceGenerator.js +82 -27
- package/lib/asset/RawDataUrlModule.js +5 -4
- package/lib/buildChunkGraph.js +2 -2
- package/lib/cache/PackFileCacheStrategy.js +69 -31
- package/lib/cache/ResolverCachePlugin.js +248 -173
- package/lib/config/defaults.js +134 -126
- package/lib/container/ContainerEntryModule.js +3 -4
- package/lib/container/ContainerPlugin.js +8 -0
- package/lib/container/FallbackModule.js +2 -2
- package/lib/container/HoistContainerReferencesPlugin.js +250 -0
- package/lib/container/ModuleFederationPlugin.js +38 -1
- package/lib/container/RemoteModule.js +4 -2
- package/lib/container/RemoteRuntimeModule.js +4 -2
- package/lib/css/CssExportsGenerator.js +16 -12
- package/lib/css/CssGenerator.js +22 -16
- package/lib/css/CssLoadingRuntimeModule.js +7 -6
- package/lib/css/CssModulesPlugin.js +122 -77
- package/lib/css/CssParser.js +655 -526
- package/lib/css/walkCssTokens.js +1168 -338
- package/lib/debug/ProfilingPlugin.js +5 -0
- package/lib/dependencies/CommonJsExportsParserPlugin.js +5 -2
- package/lib/dependencies/CommonJsImportsParserPlugin.js +3 -6
- package/lib/dependencies/CssExportDependency.js +3 -3
- package/lib/dependencies/CssLocalIdentifierDependency.js +26 -17
- package/lib/dependencies/CssUrlDependency.js +33 -3
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +3 -3
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +39 -14
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +15 -82
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +5 -2
- package/lib/dependencies/ImportParserPlugin.js +9 -7
- package/lib/dependencies/LoaderPlugin.js +19 -0
- package/lib/dependencies/SystemPlugin.js +2 -1
- package/lib/dependencies/URLPlugin.js +7 -1
- package/lib/dependencies/WorkerPlugin.js +1 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +4 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +1 -0
- package/lib/hmr/LazyCompilationPlugin.js +16 -4
- package/lib/hmr/lazyCompilationBackend.js +1 -7
- package/lib/index.js +37 -7
- package/lib/javascript/EnableChunkLoadingPlugin.js +2 -2
- package/lib/javascript/JavascriptGenerator.js +8 -8
- package/lib/javascript/JavascriptModulesPlugin.js +126 -73
- package/lib/javascript/JavascriptParser.js +338 -117
- package/lib/json/JsonGenerator.js +5 -5
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ExportPropertyLibraryPlugin.js +1 -1
- package/lib/library/UmdLibraryPlugin.js +16 -8
- package/lib/logging/Logger.js +11 -11
- package/lib/logging/createConsoleLogger.js +14 -14
- package/lib/logging/truncateArgs.js +1 -1
- package/lib/node/NodeWatchFileSystem.js +3 -1
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +20 -18
- package/lib/node/ReadFileCompileWasmPlugin.js +1 -2
- package/lib/node/nodeConsole.js +11 -8
- package/lib/optimize/AggressiveSplittingPlugin.js +21 -7
- package/lib/optimize/ConcatenatedModule.js +43 -145
- package/lib/optimize/FlagIncludedChunksPlugin.js +6 -0
- package/lib/optimize/InnerGraphPlugin.js +57 -16
- package/lib/optimize/LimitChunkCountPlugin.js +2 -4
- package/lib/optimize/ModuleConcatenationPlugin.js +4 -2
- package/lib/optimize/RealContentHashPlugin.js +1 -1
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -3
- package/lib/rules/RuleSetCompiler.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +2 -2
- package/lib/schemes/DataUriPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +32 -19
- package/lib/serialization/ObjectMiddleware.js +23 -9
- package/lib/serialization/SerializerMiddleware.js +3 -2
- package/lib/serialization/types.js +2 -2
- package/lib/sharing/ConsumeSharedModule.js +2 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +3 -1
- package/lib/sharing/ProvideSharedModule.js +2 -3
- package/lib/stats/DefaultStatsFactoryPlugin.js +22 -20
- package/lib/stats/StatsFactory.js +12 -12
- package/lib/stats/StatsPrinter.js +7 -7
- package/lib/util/AsyncQueue.js +17 -1
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/SetHelpers.js +1 -1
- package/lib/util/cleverMerge.js +48 -24
- package/lib/util/concatenate.js +227 -0
- package/lib/util/create-schema-validation.js +22 -9
- package/lib/util/deprecation.js +86 -28
- package/lib/util/fs.js +9 -9
- package/lib/util/hash/wasm-hash.js +12 -1
- package/lib/util/magicComment.js +21 -0
- package/lib/util/makeSerializable.js +24 -1
- package/lib/util/memoize.js +2 -1
- package/lib/util/runtime.js +4 -1
- package/lib/util/semver.js +130 -23
- package/lib/wasm/EnableWasmLoadingPlugin.js +2 -2
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +3 -3
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +5 -5
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +5 -5
- package/lib/wasm-sync/WebAssemblyGenerator.js +8 -9
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +5 -5
- package/lib/web/FetchCompileAsyncWasmPlugin.js +1 -2
- package/lib/web/FetchCompileWasmPlugin.js +1 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +6 -6
- package/package.json +18 -19
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +8 -2
- package/types.d.ts +801 -259
- package/lib/util/mergeScope.js +0 -76
@@ -54,11 +54,29 @@ const CssParser = require("./CssParser");
|
|
54
54
|
/** @typedef {import("../Template").RuntimeTemplate} RuntimeTemplate */
|
55
55
|
/** @typedef {import("../TemplatedPathPlugin").TemplatePath} TemplatePath */
|
56
56
|
/** @typedef {import("../util/Hash")} Hash */
|
57
|
+
/** @typedef {import("../util/createHash").Algorithm} Algorithm */
|
57
58
|
/** @typedef {import("../util/memoize")} Memoize */
|
58
59
|
|
60
|
+
/**
|
61
|
+
* @typedef {object} RenderContext
|
62
|
+
* @property {Chunk} chunk the chunk
|
63
|
+
* @property {ChunkGraph} chunkGraph the chunk graph
|
64
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
65
|
+
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
66
|
+
* @property {string} uniqueName the unique name
|
67
|
+
* @property {boolean} cssHeadDataCompression need compress
|
68
|
+
* @property {string} undoPath undo path to css file
|
69
|
+
* @property {CssModule[]} modules modules
|
70
|
+
*/
|
71
|
+
|
59
72
|
/**
|
60
73
|
* @typedef {object} ChunkRenderContext
|
61
|
-
* @property {
|
74
|
+
* @property {Chunk} chunk the chunk
|
75
|
+
* @property {ChunkGraph} chunkGraph the chunk graph
|
76
|
+
* @property {CodeGenerationResults} codeGenerationResults results of code generation
|
77
|
+
* @property {RuntimeTemplate} runtimeTemplate the runtime template
|
78
|
+
* @property {string[]} metaData meta data for runtime
|
79
|
+
* @property {string} undoPath undo path to css file
|
62
80
|
*/
|
63
81
|
|
64
82
|
/**
|
@@ -278,14 +296,13 @@ class CssModulesPlugin {
|
|
278
296
|
const { namedExports } = parserOptions;
|
279
297
|
|
280
298
|
switch (type) {
|
281
|
-
case
|
282
|
-
case CSS_MODULE_TYPE_AUTO:
|
299
|
+
case CSS_MODULE_TYPE:
|
283
300
|
return new CssParser({
|
284
301
|
namedExports
|
285
302
|
});
|
286
|
-
case
|
303
|
+
case CSS_MODULE_TYPE_GLOBAL:
|
287
304
|
return new CssParser({
|
288
|
-
|
305
|
+
defaultMode: "global",
|
289
306
|
namedExports
|
290
307
|
});
|
291
308
|
case CSS_MODULE_TYPE_MODULE:
|
@@ -293,6 +310,11 @@ class CssModulesPlugin {
|
|
293
310
|
defaultMode: "local",
|
294
311
|
namedExports
|
295
312
|
});
|
313
|
+
case CSS_MODULE_TYPE_AUTO:
|
314
|
+
return new CssParser({
|
315
|
+
defaultMode: "auto",
|
316
|
+
namedExports
|
317
|
+
});
|
296
318
|
}
|
297
319
|
});
|
298
320
|
normalModuleFactory.hooks.createGenerator
|
@@ -329,8 +351,7 @@ class CssModulesPlugin {
|
|
329
351
|
let inheritance;
|
330
352
|
|
331
353
|
if (
|
332
|
-
|
333
|
-
parent.cssLayer !== undefined) ||
|
354
|
+
parent.cssLayer !== undefined ||
|
334
355
|
parent.supports ||
|
335
356
|
parent.media
|
336
357
|
) {
|
@@ -405,7 +426,7 @@ class CssModulesPlugin {
|
|
405
426
|
hashFunction
|
406
427
|
}
|
407
428
|
} = compilation;
|
408
|
-
const hash = createHash(hashFunction);
|
429
|
+
const hash = createHash(/** @type {Algorithm} */ (hashFunction));
|
409
430
|
if (hashSalt) hash.update(hashSalt);
|
410
431
|
hooks.chunkHash.call(chunk, hash, {
|
411
432
|
chunkGraph,
|
@@ -420,7 +441,11 @@ class CssModulesPlugin {
|
|
420
441
|
}
|
421
442
|
}
|
422
443
|
const digest = /** @type {string} */ (hash.digest(hashDigest));
|
423
|
-
chunk.contentHash.css = nonNumericOnlyHash(
|
444
|
+
chunk.contentHash.css = nonNumericOnlyHash(
|
445
|
+
digest,
|
446
|
+
/** @type {number} */
|
447
|
+
(hashDigestLength)
|
448
|
+
);
|
424
449
|
});
|
425
450
|
compilation.hooks.renderManifest.tap(PLUGIN_NAME, (result, options) => {
|
426
451
|
const { chunkGraph } = compilation;
|
@@ -446,23 +471,26 @@ class CssModulesPlugin {
|
|
446
471
|
);
|
447
472
|
const undoPath = getUndoPath(
|
448
473
|
filename,
|
449
|
-
|
474
|
+
/** @type {string} */
|
475
|
+
(compilation.outputOptions.path),
|
450
476
|
false
|
451
477
|
);
|
452
478
|
result.push({
|
453
479
|
render: () =>
|
454
|
-
this.renderChunk(
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
480
|
+
this.renderChunk(
|
481
|
+
{
|
482
|
+
chunk,
|
483
|
+
chunkGraph,
|
484
|
+
codeGenerationResults,
|
485
|
+
uniqueName: compilation.outputOptions.uniqueName,
|
486
|
+
cssHeadDataCompression:
|
487
|
+
compilation.outputOptions.cssHeadDataCompression,
|
488
|
+
undoPath,
|
489
|
+
modules,
|
490
|
+
runtimeTemplate
|
491
|
+
},
|
464
492
|
hooks
|
465
|
-
|
493
|
+
),
|
466
494
|
filename,
|
467
495
|
info,
|
468
496
|
identifier: `css${chunk.id}`,
|
@@ -494,9 +522,6 @@ class CssModulesPlugin {
|
|
494
522
|
onceForChunkSet.add(chunk);
|
495
523
|
if (!isEnabledForChunk(chunk)) return;
|
496
524
|
|
497
|
-
set.add(RuntimeGlobals.publicPath);
|
498
|
-
set.add(RuntimeGlobals.getChunkCssFilename);
|
499
|
-
set.add(RuntimeGlobals.hasOwnProperty);
|
500
525
|
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
501
526
|
set.add(RuntimeGlobals.makeNamespaceObject);
|
502
527
|
|
@@ -508,10 +533,45 @@ class CssModulesPlugin {
|
|
508
533
|
.tap(PLUGIN_NAME, handler);
|
509
534
|
compilation.hooks.runtimeRequirementInTree
|
510
535
|
.for(RuntimeGlobals.ensureChunkHandlers)
|
511
|
-
.tap(PLUGIN_NAME,
|
536
|
+
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
537
|
+
if (!isEnabledForChunk(chunk)) return;
|
538
|
+
if (
|
539
|
+
!chunkGraph.hasModuleInGraph(
|
540
|
+
chunk,
|
541
|
+
m =>
|
542
|
+
m.type === CSS_MODULE_TYPE ||
|
543
|
+
m.type === CSS_MODULE_TYPE_GLOBAL ||
|
544
|
+
m.type === CSS_MODULE_TYPE_MODULE ||
|
545
|
+
m.type === CSS_MODULE_TYPE_AUTO
|
546
|
+
)
|
547
|
+
) {
|
548
|
+
return;
|
549
|
+
}
|
550
|
+
|
551
|
+
set.add(RuntimeGlobals.hasOwnProperty);
|
552
|
+
set.add(RuntimeGlobals.publicPath);
|
553
|
+
set.add(RuntimeGlobals.getChunkCssFilename);
|
554
|
+
});
|
512
555
|
compilation.hooks.runtimeRequirementInTree
|
513
556
|
.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
|
514
|
-
.tap(PLUGIN_NAME,
|
557
|
+
.tap(PLUGIN_NAME, (chunk, set, { chunkGraph }) => {
|
558
|
+
if (!isEnabledForChunk(chunk)) return;
|
559
|
+
if (
|
560
|
+
!chunkGraph.hasModuleInGraph(
|
561
|
+
chunk,
|
562
|
+
m =>
|
563
|
+
m.type === CSS_MODULE_TYPE ||
|
564
|
+
m.type === CSS_MODULE_TYPE_GLOBAL ||
|
565
|
+
m.type === CSS_MODULE_TYPE_MODULE ||
|
566
|
+
m.type === CSS_MODULE_TYPE_AUTO
|
567
|
+
)
|
568
|
+
) {
|
569
|
+
return;
|
570
|
+
}
|
571
|
+
set.add(RuntimeGlobals.publicPath);
|
572
|
+
set.add(RuntimeGlobals.getChunkCssFilename);
|
573
|
+
set.add(RuntimeGlobals.moduleFactoriesAddOnly);
|
574
|
+
});
|
515
575
|
}
|
516
576
|
);
|
517
577
|
}
|
@@ -549,6 +609,11 @@ class CssModulesPlugin {
|
|
549
609
|
if (modulesByChunkGroup.length === 1)
|
550
610
|
return modulesByChunkGroup[0].list.reverse();
|
551
611
|
|
612
|
+
/**
|
613
|
+
* @param {{ list: Module[] }} a a
|
614
|
+
* @param {{ list: Module[] }} b b
|
615
|
+
* @returns {-1 | 0 | 1} result
|
616
|
+
*/
|
552
617
|
const compareModuleLists = ({ list: a }, { list: b }) => {
|
553
618
|
if (a.length === 0) {
|
554
619
|
return b.length === 0 ? 0 : 1;
|
@@ -657,27 +722,14 @@ class CssModulesPlugin {
|
|
657
722
|
}
|
658
723
|
|
659
724
|
/**
|
660
|
-
* @param {
|
661
|
-
* @param {
|
662
|
-
* @param {
|
663
|
-
* @param {Chunk} options.chunk chunk
|
664
|
-
* @param {ChunkGraph} options.chunkGraph chunk graph
|
665
|
-
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
666
|
-
* @param {CssModule} options.module css module
|
667
|
-
* @param {RuntimeTemplate} options.runtimeTemplate runtime template
|
668
|
-
* @param {CompilationHooks} options.hooks hooks
|
725
|
+
* @param {CssModule} module css module
|
726
|
+
* @param {ChunkRenderContext} renderContext options object
|
727
|
+
* @param {CompilationHooks} hooks hooks
|
669
728
|
* @returns {Source} css module source
|
670
729
|
*/
|
671
|
-
renderModule({
|
672
|
-
metaData
|
673
|
-
|
674
|
-
chunk,
|
675
|
-
chunkGraph,
|
676
|
-
codeGenerationResults,
|
677
|
-
module,
|
678
|
-
hooks,
|
679
|
-
runtimeTemplate
|
680
|
-
}) {
|
730
|
+
renderModule(module, renderContext, hooks) {
|
731
|
+
const { codeGenerationResults, chunk, undoPath, chunkGraph, metaData } =
|
732
|
+
renderContext;
|
681
733
|
const codeGenResult = codeGenerationResults.get(module, chunk.runtime);
|
682
734
|
const moduleSourceContent =
|
683
735
|
/** @type {Source} */
|
@@ -791,53 +843,46 @@ class CssModulesPlugin {
|
|
791
843
|
}${esModule ? "&" : ""}${escapeCss(moduleId)}`
|
792
844
|
);
|
793
845
|
return tryRunOrWebpackError(
|
794
|
-
() =>
|
795
|
-
hooks.renderModulePackage.call(source, module, {
|
796
|
-
runtimeTemplate
|
797
|
-
}),
|
846
|
+
() => hooks.renderModulePackage.call(source, module, renderContext),
|
798
847
|
"CssModulesPlugin.getCompilationHooks().renderModulePackage"
|
799
848
|
);
|
800
849
|
}
|
801
850
|
|
802
851
|
/**
|
803
|
-
* @param {
|
804
|
-
* @param {
|
805
|
-
* @param {boolean | undefined} options.cssHeadDataCompression compress css head data
|
806
|
-
* @param {string} options.undoPath undo path for public path auto
|
807
|
-
* @param {Chunk} options.chunk chunk
|
808
|
-
* @param {ChunkGraph} options.chunkGraph chunk graph
|
809
|
-
* @param {CodeGenerationResults} options.codeGenerationResults code generation results
|
810
|
-
* @param {CssModule[]} options.modules ordered css modules
|
811
|
-
* @param {RuntimeTemplate} options.runtimeTemplate runtime template
|
812
|
-
* @param {CompilationHooks} options.hooks hooks
|
852
|
+
* @param {RenderContext} renderContext the render context
|
853
|
+
* @param {CompilationHooks} hooks hooks
|
813
854
|
* @returns {Source} generated source
|
814
855
|
*/
|
815
|
-
renderChunk(
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
856
|
+
renderChunk(
|
857
|
+
{
|
858
|
+
uniqueName,
|
859
|
+
cssHeadDataCompression,
|
860
|
+
undoPath,
|
861
|
+
chunk,
|
862
|
+
chunkGraph,
|
863
|
+
codeGenerationResults,
|
864
|
+
modules,
|
865
|
+
runtimeTemplate
|
866
|
+
},
|
824
867
|
hooks
|
825
|
-
|
868
|
+
) {
|
826
869
|
const source = new ConcatSource();
|
827
870
|
/** @type {string[]} */
|
828
871
|
const metaData = [];
|
829
872
|
for (const module of modules) {
|
830
873
|
try {
|
831
|
-
const moduleSource = this.renderModule(
|
832
|
-
metaData,
|
833
|
-
undoPath,
|
834
|
-
chunk,
|
835
|
-
chunkGraph,
|
836
|
-
codeGenerationResults,
|
874
|
+
const moduleSource = this.renderModule(
|
837
875
|
module,
|
838
|
-
|
876
|
+
{
|
877
|
+
metaData,
|
878
|
+
undoPath,
|
879
|
+
chunk,
|
880
|
+
chunkGraph,
|
881
|
+
codeGenerationResults,
|
882
|
+
runtimeTemplate
|
883
|
+
},
|
839
884
|
hooks
|
840
|
-
|
885
|
+
);
|
841
886
|
source.add(moduleSource);
|
842
887
|
} catch (err) {
|
843
888
|
/** @type {Error} */
|