webpack 5.94.0 → 5.95.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.
- package/lib/EnvironmentPlugin.js +3 -2
- package/lib/ExternalModule.js +79 -93
- package/lib/NormalModule.js +4 -0
- package/lib/TemplatedPathPlugin.js +9 -3
- package/lib/buildChunkGraph.js +79 -62
- package/lib/config/defaults.js +1 -0
- package/lib/dependencies/ContextDependency.js +6 -1
- package/lib/dependencies/ContextElementDependency.js +33 -6
- package/lib/javascript/JavascriptModulesPlugin.js +43 -18
- package/lib/optimize/ConcatenatedModule.js +1 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/util/LazySet.js +12 -0
- package/lib/util/fs.js +1 -1
- package/lib/util/runtime.js +6 -0
- package/package.json +4 -4
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +17 -11
package/lib/EnvironmentPlugin.js
CHANGED
@@ -13,15 +13,16 @@ const WebpackError = require("./WebpackError");
|
|
13
13
|
|
14
14
|
class EnvironmentPlugin {
|
15
15
|
/**
|
16
|
-
* @param {(string | string[] | Record<string,
|
16
|
+
* @param {(string | string[] | Record<string, any>)[]} keys keys
|
17
17
|
*/
|
18
18
|
constructor(...keys) {
|
19
19
|
if (keys.length === 1 && Array.isArray(keys[0])) {
|
20
|
+
/** @type {string[]} */
|
20
21
|
this.keys = keys[0];
|
21
22
|
this.defaultValues = {};
|
22
23
|
} else if (keys.length === 1 && keys[0] && typeof keys[0] === "object") {
|
23
24
|
this.keys = Object.keys(keys[0]);
|
24
|
-
this.defaultValues = /** @type {Record<string,
|
25
|
+
this.defaultValues = /** @type {Record<string, any>} */ (keys[0]);
|
25
26
|
} else {
|
26
27
|
this.keys = /** @type {string[]} */ (keys);
|
27
28
|
this.defaultValues = {};
|
package/lib/ExternalModule.js
CHANGED
@@ -526,7 +526,7 @@ class ExternalModule extends Module {
|
|
526
526
|
* @returns {string} a unique identifier of the module
|
527
527
|
*/
|
528
528
|
identifier() {
|
529
|
-
return `external ${this.externalType} ${JSON.stringify(this.request)}`;
|
529
|
+
return `external ${this._resolveExternalType(this.externalType)} ${JSON.stringify(this.request)}`;
|
530
530
|
}
|
531
531
|
|
532
532
|
/**
|
@@ -546,25 +546,6 @@ class ExternalModule extends Module {
|
|
546
546
|
return callback(null, !this.buildMeta);
|
547
547
|
}
|
548
548
|
|
549
|
-
/**
|
550
|
-
* @param {string} externalType raw external type
|
551
|
-
* @returns {string} resolved external type
|
552
|
-
*/
|
553
|
-
getModuleImportType(externalType) {
|
554
|
-
if (externalType === "module-import") {
|
555
|
-
if (
|
556
|
-
this.dependencyMeta &&
|
557
|
-
/** @type {ImportDependencyMeta} */ (this.dependencyMeta).externalType
|
558
|
-
) {
|
559
|
-
return /** @type {ImportDependencyMeta} */ (this.dependencyMeta)
|
560
|
-
.externalType;
|
561
|
-
}
|
562
|
-
return "module";
|
563
|
-
}
|
564
|
-
|
565
|
-
return externalType;
|
566
|
-
}
|
567
|
-
|
568
549
|
/**
|
569
550
|
* @param {WebpackOptions} options webpack options
|
570
551
|
* @param {Compilation} compilation the compilation
|
@@ -597,6 +578,25 @@ class ExternalModule extends Module {
|
|
597
578
|
canMangle = true;
|
598
579
|
}
|
599
580
|
break;
|
581
|
+
case "module":
|
582
|
+
if (this.buildInfo.module) {
|
583
|
+
if (!Array.isArray(request) || request.length === 1) {
|
584
|
+
this.buildMeta.exportsType = "namespace";
|
585
|
+
canMangle = true;
|
586
|
+
}
|
587
|
+
} else {
|
588
|
+
this.buildMeta.async = true;
|
589
|
+
EnvironmentNotSupportAsyncWarning.check(
|
590
|
+
this,
|
591
|
+
compilation.runtimeTemplate,
|
592
|
+
"external module"
|
593
|
+
);
|
594
|
+
if (!Array.isArray(request) || request.length === 1) {
|
595
|
+
this.buildMeta.exportsType = "namespace";
|
596
|
+
canMangle = false;
|
597
|
+
}
|
598
|
+
}
|
599
|
+
break;
|
600
600
|
case "script":
|
601
601
|
this.buildMeta.async = true;
|
602
602
|
EnvironmentNotSupportAsyncWarning.check(
|
@@ -613,45 +613,18 @@ class ExternalModule extends Module {
|
|
613
613
|
"external promise"
|
614
614
|
);
|
615
615
|
break;
|
616
|
-
case "module":
|
617
616
|
case "import":
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
this.buildMeta.async = true;
|
628
|
-
EnvironmentNotSupportAsyncWarning.check(
|
629
|
-
this,
|
630
|
-
compilation.runtimeTemplate,
|
631
|
-
"external module"
|
632
|
-
);
|
633
|
-
if (!Array.isArray(request) || request.length === 1) {
|
634
|
-
this.buildMeta.exportsType = "namespace";
|
635
|
-
canMangle = false;
|
636
|
-
}
|
637
|
-
}
|
638
|
-
}
|
639
|
-
|
640
|
-
if (type === "import") {
|
641
|
-
this.buildMeta.async = true;
|
642
|
-
EnvironmentNotSupportAsyncWarning.check(
|
643
|
-
this,
|
644
|
-
compilation.runtimeTemplate,
|
645
|
-
"external import"
|
646
|
-
);
|
647
|
-
if (!Array.isArray(request) || request.length === 1) {
|
648
|
-
this.buildMeta.exportsType = "namespace";
|
649
|
-
canMangle = false;
|
650
|
-
}
|
617
|
+
this.buildMeta.async = true;
|
618
|
+
EnvironmentNotSupportAsyncWarning.check(
|
619
|
+
this,
|
620
|
+
compilation.runtimeTemplate,
|
621
|
+
"external import"
|
622
|
+
);
|
623
|
+
if (!Array.isArray(request) || request.length === 1) {
|
624
|
+
this.buildMeta.exportsType = "namespace";
|
625
|
+
canMangle = false;
|
651
626
|
}
|
652
|
-
|
653
627
|
break;
|
654
|
-
}
|
655
628
|
}
|
656
629
|
this.addDependency(new StaticExportsDependency(true, canMangle));
|
657
630
|
callback();
|
@@ -687,9 +660,31 @@ class ExternalModule extends Module {
|
|
687
660
|
let { request, externalType } = this;
|
688
661
|
if (typeof request === "object" && !Array.isArray(request))
|
689
662
|
request = request[externalType];
|
663
|
+
externalType = this._resolveExternalType(externalType);
|
690
664
|
return { request, externalType };
|
691
665
|
}
|
692
666
|
|
667
|
+
/**
|
668
|
+
* Resolve the detailed external type from the raw external type.
|
669
|
+
* e.g. resolve "module" or "import" from "module-import" type
|
670
|
+
* @param {string} externalType raw external type
|
671
|
+
* @returns {string} resolved external type
|
672
|
+
*/
|
673
|
+
_resolveExternalType(externalType) {
|
674
|
+
if (externalType === "module-import") {
|
675
|
+
if (
|
676
|
+
this.dependencyMeta &&
|
677
|
+
/** @type {ImportDependencyMeta} */ (this.dependencyMeta).externalType
|
678
|
+
) {
|
679
|
+
return /** @type {ImportDependencyMeta} */ (this.dependencyMeta)
|
680
|
+
.externalType;
|
681
|
+
}
|
682
|
+
return "module";
|
683
|
+
}
|
684
|
+
|
685
|
+
return externalType;
|
686
|
+
}
|
687
|
+
|
693
688
|
/**
|
694
689
|
* @private
|
695
690
|
* @param {string | string[]} request request
|
@@ -749,52 +744,43 @@ class ExternalModule extends Module {
|
|
749
744
|
runtimeTemplate
|
750
745
|
);
|
751
746
|
}
|
747
|
+
case "import":
|
748
|
+
return getSourceForImportExternal(
|
749
|
+
request,
|
750
|
+
runtimeTemplate,
|
751
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
752
|
+
);
|
752
753
|
case "script":
|
753
754
|
return getSourceForScriptExternal(request, runtimeTemplate);
|
754
|
-
case "module":
|
755
|
-
|
756
|
-
|
757
|
-
const type = this.getModuleImportType(externalType);
|
758
|
-
if (type === "import") {
|
759
|
-
return getSourceForImportExternal(
|
760
|
-
request,
|
761
|
-
runtimeTemplate,
|
762
|
-
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
763
|
-
);
|
764
|
-
}
|
765
|
-
|
766
|
-
if (type === "module") {
|
767
|
-
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
|
768
|
-
if (!runtimeTemplate.supportsDynamicImport()) {
|
769
|
-
throw new Error(
|
770
|
-
`The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
|
771
|
-
runtimeTemplate.supportsEcmaScriptModuleSyntax()
|
772
|
-
? "\nDid you mean to build a EcmaScript Module ('output.module: true')?"
|
773
|
-
: ""
|
774
|
-
}`
|
775
|
-
);
|
776
|
-
}
|
777
|
-
return getSourceForImportExternal(
|
778
|
-
request,
|
779
|
-
runtimeTemplate,
|
780
|
-
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
781
|
-
);
|
782
|
-
}
|
783
|
-
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
755
|
+
case "module": {
|
756
|
+
if (!(/** @type {BuildInfo} */ (this.buildInfo).module)) {
|
757
|
+
if (!runtimeTemplate.supportsDynamicImport()) {
|
784
758
|
throw new Error(
|
785
|
-
|
759
|
+
`The target environment doesn't support dynamic import() syntax so it's not possible to use external type 'module' within a script${
|
760
|
+
runtimeTemplate.supportsEcmaScriptModuleSyntax()
|
761
|
+
? "\nDid you mean to build a EcmaScript Module ('output.module: true')?"
|
762
|
+
: ""
|
763
|
+
}`
|
786
764
|
);
|
787
765
|
}
|
788
|
-
return
|
766
|
+
return getSourceForImportExternal(
|
789
767
|
request,
|
790
|
-
moduleGraph.getExportsInfo(this),
|
791
|
-
runtime,
|
792
768
|
runtimeTemplate,
|
793
769
|
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
794
770
|
);
|
795
771
|
}
|
796
|
-
|
797
|
-
|
772
|
+
if (!runtimeTemplate.supportsEcmaScriptModuleSyntax()) {
|
773
|
+
throw new Error(
|
774
|
+
"The target environment doesn't support EcmaScriptModule syntax so it's not possible to use external type 'module'"
|
775
|
+
);
|
776
|
+
}
|
777
|
+
return getSourceForModuleExternal(
|
778
|
+
request,
|
779
|
+
moduleGraph.getExportsInfo(this),
|
780
|
+
runtime,
|
781
|
+
runtimeTemplate,
|
782
|
+
/** @type {ImportDependencyMeta} */ (dependencyMeta)
|
783
|
+
);
|
798
784
|
}
|
799
785
|
case "var":
|
800
786
|
case "promise":
|
@@ -939,7 +925,7 @@ class ExternalModule extends Module {
|
|
939
925
|
updateHash(hash, context) {
|
940
926
|
const { chunkGraph } = context;
|
941
927
|
hash.update(
|
942
|
-
`${this.externalType}${JSON.stringify(this.request)}${this.isOptional(
|
928
|
+
`${this._resolveExternalType(this.externalType)}${JSON.stringify(this.request)}${this.isOptional(
|
943
929
|
chunkGraph.moduleGraph
|
944
930
|
)}`
|
945
931
|
);
|
package/lib/NormalModule.js
CHANGED
@@ -777,6 +777,10 @@ class NormalModule extends Module {
|
|
777
777
|
webpack: true,
|
778
778
|
sourceMap: Boolean(this.useSourceMap),
|
779
779
|
mode: options.mode || "production",
|
780
|
+
hashFunction: options.output.hashFunction,
|
781
|
+
hashDigest: options.output.hashDigest,
|
782
|
+
hashDigestLength: options.output.hashDigestLength,
|
783
|
+
hashSalt: options.output.hashSalt,
|
780
784
|
_module: this,
|
781
785
|
_compilation: compilation,
|
782
786
|
_compiler: compilation.compiler,
|
@@ -162,19 +162,25 @@ const replacePathVariables = (path, data, assetInfo) => {
|
|
162
162
|
if (match) {
|
163
163
|
const ext = mime.extension(match[1]);
|
164
164
|
const emptyReplacer = replacer("", true);
|
165
|
+
// "XXXX" used for `updateHash`, so we don't need it here
|
166
|
+
const contentHash =
|
167
|
+
data.contentHash && !/X+/.test(data.contentHash)
|
168
|
+
? data.contentHash
|
169
|
+
: false;
|
170
|
+
const baseReplacer = contentHash ? replacer(contentHash) : emptyReplacer;
|
165
171
|
|
166
172
|
replacements.set("file", emptyReplacer);
|
167
173
|
replacements.set("query", emptyReplacer);
|
168
174
|
replacements.set("fragment", emptyReplacer);
|
169
175
|
replacements.set("path", emptyReplacer);
|
170
|
-
replacements.set("base",
|
171
|
-
replacements.set("name",
|
176
|
+
replacements.set("base", baseReplacer);
|
177
|
+
replacements.set("name", baseReplacer);
|
172
178
|
replacements.set("ext", replacer(ext ? `.${ext}` : "", true));
|
173
179
|
// Legacy
|
174
180
|
replacements.set(
|
175
181
|
"filebase",
|
176
182
|
deprecated(
|
177
|
-
|
183
|
+
baseReplacer,
|
178
184
|
"[filebase] is now [base]",
|
179
185
|
"DEP_WEBPACK_TEMPLATE_PATH_PLUGIN_REPLACE_PATH_VARIABLES_FILENAME"
|
180
186
|
)
|
package/lib/buildChunkGraph.js
CHANGED
@@ -38,6 +38,7 @@ const { getEntryRuntime, mergeRuntime } = require("./util/runtime");
|
|
38
38
|
* @typedef {object} ChunkGroupInfo
|
39
39
|
* @property {ChunkGroup} chunkGroup the chunk group
|
40
40
|
* @property {RuntimeSpec} runtime the runtimes
|
41
|
+
* @property {boolean} initialized is this chunk group initialized
|
41
42
|
* @property {bigint | undefined} minAvailableModules current minimal set of modules available at this point
|
42
43
|
* @property {bigint[]} availableModulesToBeMerged enqueued updates to the minimal set of available modules
|
43
44
|
* @property {Set<Module>=} skippedItems modules that were skipped because module is already available in parent chunks (need to reconsider when minAvailableModules is shrinking)
|
@@ -345,8 +346,8 @@ const visitModules = (
|
|
345
346
|
/** @type {Map<DependenciesBlock, ChunkGroupInfo>} */
|
346
347
|
const blockChunkGroups = new Map();
|
347
348
|
|
348
|
-
/** @type {Map<ChunkGroupInfo, DependenciesBlock
|
349
|
-
const
|
349
|
+
/** @type {Map<ChunkGroupInfo, Set<DependenciesBlock>>} */
|
350
|
+
const blocksByChunkGroups = new Map();
|
350
351
|
|
351
352
|
/** @type {Map<string, ChunkGroupInfo>} */
|
352
353
|
const namedChunkGroups = new Map();
|
@@ -367,7 +368,7 @@ const visitModules = (
|
|
367
368
|
/** @type {QueueItem[]} */
|
368
369
|
let queue = [];
|
369
370
|
|
370
|
-
/** @type {Map<ChunkGroupInfo, Set<ChunkGroupInfo>>} */
|
371
|
+
/** @type {Map<ChunkGroupInfo, Set<[ChunkGroupInfo, QueueItem | null]>>} */
|
371
372
|
const queueConnect = new Map();
|
372
373
|
/** @type {Set<ChunkGroupInfo>} */
|
373
374
|
const chunkGroupsForCombining = new Set();
|
@@ -382,6 +383,7 @@ const visitModules = (
|
|
382
383
|
);
|
383
384
|
/** @type {ChunkGroupInfo} */
|
384
385
|
const chunkGroupInfo = {
|
386
|
+
initialized: false,
|
385
387
|
chunkGroup,
|
386
388
|
runtime,
|
387
389
|
minAvailableModules: undefined,
|
@@ -452,7 +454,7 @@ const visitModules = (
|
|
452
454
|
|
453
455
|
/** @type {Set<ChunkGroupInfo>} */
|
454
456
|
const outdatedChunkGroupInfo = new Set();
|
455
|
-
/** @type {Set<ChunkGroupInfo>} */
|
457
|
+
/** @type {Set<[ChunkGroupInfo, QueueItem]>} */
|
456
458
|
const chunkGroupsForMerging = new Set();
|
457
459
|
/** @type {QueueItem[]} */
|
458
460
|
let queueDelayed = [];
|
@@ -505,6 +507,7 @@ const visitModules = (
|
|
505
507
|
entrypoint.index = nextChunkGroupIndex++;
|
506
508
|
cgi = {
|
507
509
|
chunkGroup: entrypoint,
|
510
|
+
initialized: false,
|
508
511
|
runtime: entrypoint.options.runtime || entrypoint.name,
|
509
512
|
minAvailableModules: ZERO_BIGINT,
|
510
513
|
availableModulesToBeMerged: [],
|
@@ -572,6 +575,7 @@ const visitModules = (
|
|
572
575
|
maskByChunk.set(c.chunks[0], ZERO_BIGINT);
|
573
576
|
c.index = nextChunkGroupIndex++;
|
574
577
|
cgi = {
|
578
|
+
initialized: false,
|
575
579
|
chunkGroup: c,
|
576
580
|
runtime: chunkGroupInfo.runtime,
|
577
581
|
minAvailableModules: undefined,
|
@@ -614,7 +618,6 @@ const visitModules = (
|
|
614
618
|
blockConnections.set(b, []);
|
615
619
|
}
|
616
620
|
blockChunkGroups.set(b, /** @type {ChunkGroupInfo} */ (cgi));
|
617
|
-
blockByChunkGroups.set(/** @type {ChunkGroupInfo} */ (cgi), b);
|
618
621
|
} else if (entryOptions) {
|
619
622
|
entrypoint = /** @type {Entrypoint} */ (cgi.chunkGroup);
|
620
623
|
} else {
|
@@ -636,19 +639,17 @@ const visitModules = (
|
|
636
639
|
connectList = new Set();
|
637
640
|
queueConnect.set(chunkGroupInfo, connectList);
|
638
641
|
}
|
639
|
-
connectList.add(
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
chunkGroupInfo: /** @type {ChunkGroupInfo} */ (cgi)
|
651
|
-
});
|
642
|
+
connectList.add([
|
643
|
+
cgi,
|
644
|
+
{
|
645
|
+
action: PROCESS_BLOCK,
|
646
|
+
block: b,
|
647
|
+
module,
|
648
|
+
chunk: c.chunks[0],
|
649
|
+
chunkGroup: c,
|
650
|
+
chunkGroupInfo: /** @type {ChunkGroupInfo} */ (cgi)
|
651
|
+
}
|
652
|
+
]);
|
652
653
|
} else if (entrypoint !== undefined) {
|
653
654
|
chunkGroupInfo.chunkGroup.addAsyncEntrypoint(entrypoint);
|
654
655
|
}
|
@@ -901,11 +902,10 @@ const visitModules = (
|
|
901
902
|
for (const [chunkGroupInfo, targets] of queueConnect) {
|
902
903
|
// 1. Add new targets to the list of children
|
903
904
|
if (chunkGroupInfo.children === undefined) {
|
904
|
-
chunkGroupInfo.children =
|
905
|
-
}
|
906
|
-
|
907
|
-
|
908
|
-
}
|
905
|
+
chunkGroupInfo.children = new Set();
|
906
|
+
}
|
907
|
+
for (const [target] of targets) {
|
908
|
+
chunkGroupInfo.children.add(target);
|
909
909
|
}
|
910
910
|
|
911
911
|
// 2. Calculate resulting available modules
|
@@ -915,9 +915,9 @@ const visitModules = (
|
|
915
915
|
const runtime = chunkGroupInfo.runtime;
|
916
916
|
|
917
917
|
// 3. Update chunk group info
|
918
|
-
for (const target of targets) {
|
918
|
+
for (const [target, processBlock] of targets) {
|
919
919
|
target.availableModulesToBeMerged.push(resultingAvailableModules);
|
920
|
-
chunkGroupsForMerging.add(target);
|
920
|
+
chunkGroupsForMerging.add([target, processBlock]);
|
921
921
|
const oldRuntime = target.runtime;
|
922
922
|
const newRuntime = mergeRuntime(oldRuntime, runtime);
|
923
923
|
if (oldRuntime !== newRuntime) {
|
@@ -935,7 +935,7 @@ const visitModules = (
|
|
935
935
|
statProcessedChunkGroupsForMerging += chunkGroupsForMerging.size;
|
936
936
|
|
937
937
|
// Execute the merge
|
938
|
-
for (const info of chunkGroupsForMerging) {
|
938
|
+
for (const [info, processBlock] of chunkGroupsForMerging) {
|
939
939
|
const availableModulesToBeMerged = info.availableModulesToBeMerged;
|
940
940
|
const cachedMinAvailableModules = info.minAvailableModules;
|
941
941
|
let minAvailableModules = cachedMinAvailableModules;
|
@@ -958,6 +958,27 @@ const visitModules = (
|
|
958
958
|
info.resultingAvailableModules = undefined;
|
959
959
|
outdatedChunkGroupInfo.add(info);
|
960
960
|
}
|
961
|
+
|
962
|
+
if (processBlock) {
|
963
|
+
let blocks = blocksByChunkGroups.get(info);
|
964
|
+
if (!blocks) {
|
965
|
+
blocksByChunkGroups.set(info, (blocks = new Set()));
|
966
|
+
}
|
967
|
+
|
968
|
+
// Whether to walk block depends on minAvailableModules and input block.
|
969
|
+
// We can treat creating chunk group as a function with 2 input, entry block and minAvailableModules
|
970
|
+
// If input is the same, we can skip re-walk
|
971
|
+
let needWalkBlock = !info.initialized || changed;
|
972
|
+
if (!blocks.has(processBlock.block)) {
|
973
|
+
needWalkBlock = true;
|
974
|
+
blocks.add(processBlock.block);
|
975
|
+
}
|
976
|
+
|
977
|
+
if (needWalkBlock) {
|
978
|
+
info.initialized = true;
|
979
|
+
queueDelayed.push(processBlock);
|
980
|
+
}
|
981
|
+
}
|
961
982
|
}
|
962
983
|
chunkGroupsForMerging.clear();
|
963
984
|
};
|
@@ -1057,7 +1078,7 @@ const visitModules = (
|
|
1057
1078
|
connectList = new Set();
|
1058
1079
|
queueConnect.set(info, connectList);
|
1059
1080
|
}
|
1060
|
-
connectList.add(cgi);
|
1081
|
+
connectList.add([cgi, null]);
|
1061
1082
|
}
|
1062
1083
|
}
|
1063
1084
|
|
@@ -1117,48 +1138,44 @@ const visitModules = (
|
|
1117
1138
|
for (const info of outdatedOrderIndexChunkGroups) {
|
1118
1139
|
const { chunkGroup, runtime } = info;
|
1119
1140
|
|
1120
|
-
const
|
1141
|
+
const blocks = blocksByChunkGroups.get(info);
|
1121
1142
|
|
1122
|
-
if (!
|
1143
|
+
if (!blocks) {
|
1123
1144
|
continue;
|
1124
1145
|
}
|
1125
1146
|
|
1126
|
-
|
1127
|
-
|
1128
|
-
|
1129
|
-
|
1130
|
-
|
1131
|
-
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
|
1136
|
-
|
1137
|
-
|
1138
|
-
|
1139
|
-
|
1140
|
-
|
1141
|
-
|
1142
|
-
|
1143
|
-
|
1144
|
-
|
1145
|
-
|
1146
|
-
const refModule = /** @type {Module} */ (blockModules[i]);
|
1147
|
-
if (visited.has(refModule)) {
|
1148
|
-
continue;
|
1149
|
-
}
|
1147
|
+
for (const block of blocks) {
|
1148
|
+
let preOrderIndex = 0;
|
1149
|
+
let postOrderIndex = 0;
|
1150
|
+
/**
|
1151
|
+
* @param {DependenciesBlock} current current
|
1152
|
+
* @param {BlocksWithNestedBlocks} visited visited dependencies blocks
|
1153
|
+
*/
|
1154
|
+
const process = (current, visited) => {
|
1155
|
+
const blockModules = getBlockModules(current, runtime);
|
1156
|
+
for (let i = 0, len = blockModules.length; i < len; i += 3) {
|
1157
|
+
const activeState = /** @type {ConnectionState} */ (
|
1158
|
+
blockModules[i + 1]
|
1159
|
+
);
|
1160
|
+
if (activeState === false) {
|
1161
|
+
continue;
|
1162
|
+
}
|
1163
|
+
const refModule = /** @type {Module} */ (blockModules[i]);
|
1164
|
+
if (visited.has(refModule)) {
|
1165
|
+
continue;
|
1166
|
+
}
|
1150
1167
|
|
1151
|
-
|
1168
|
+
visited.add(refModule);
|
1152
1169
|
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
|
1170
|
+
if (refModule) {
|
1171
|
+
chunkGroup.setModulePreOrderIndex(refModule, preOrderIndex++);
|
1172
|
+
process(refModule, visited);
|
1173
|
+
chunkGroup.setModulePostOrderIndex(refModule, postOrderIndex++);
|
1174
|
+
}
|
1157
1175
|
}
|
1158
|
-
}
|
1159
|
-
|
1160
|
-
|
1161
|
-
process(block, new Set());
|
1176
|
+
};
|
1177
|
+
process(block, new Set());
|
1178
|
+
}
|
1162
1179
|
}
|
1163
1180
|
outdatedOrderIndexChunkGroups.clear();
|
1164
1181
|
ordinalByModule.clear();
|
package/lib/config/defaults.js
CHANGED
@@ -1434,6 +1434,7 @@ const applyOptimizationDefaults = (
|
|
1434
1434
|
D(optimization, "innerGraph", production);
|
1435
1435
|
D(optimization, "mangleExports", production);
|
1436
1436
|
D(optimization, "concatenateModules", production);
|
1437
|
+
D(optimization, "avoidEntryIife", production);
|
1437
1438
|
D(optimization, "runtimeChunk", false);
|
1438
1439
|
D(optimization, "emitOnErrors", !production);
|
1439
1440
|
D(optimization, "checkWasmTypes", production);
|
@@ -91,7 +91,12 @@ class ContextDependency extends Dependency {
|
|
91
91
|
this.options.include
|
92
92
|
)} ${regExpToString(this.options.exclude)} ` +
|
93
93
|
`${this.options.mode} ${this.options.chunkName} ` +
|
94
|
-
`${JSON.stringify(this.options.groupOptions)}`
|
94
|
+
`${JSON.stringify(this.options.groupOptions)}` +
|
95
|
+
`${
|
96
|
+
this.options.referencedExports
|
97
|
+
? ` ${JSON.stringify(this.options.referencedExports)}`
|
98
|
+
: ""
|
99
|
+
}`
|
95
100
|
);
|
96
101
|
}
|
97
102
|
|
@@ -9,7 +9,10 @@ const Dependency = require("../Dependency");
|
|
9
9
|
const makeSerializable = require("../util/makeSerializable");
|
10
10
|
const ModuleDependency = require("./ModuleDependency");
|
11
11
|
|
12
|
+
/** @typedef {import("../ContextModule")} ContextModule */
|
12
13
|
/** @typedef {import("../Dependency").ReferencedExport} ReferencedExport */
|
14
|
+
/** @typedef {import("../Module")} Module */
|
15
|
+
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
13
16
|
/** @typedef {import("../ModuleGraph")} ModuleGraph */
|
14
17
|
/** @typedef {import("../javascript/JavascriptParser").ImportAttributes} ImportAttributes */
|
15
18
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
@@ -67,12 +70,36 @@ class ContextElementDependency extends ModuleDependency {
|
|
67
70
|
* @returns {(string[] | ReferencedExport)[]} referenced exports
|
68
71
|
*/
|
69
72
|
getReferencedExports(moduleGraph, runtime) {
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
if (!this.referencedExports) return Dependency.EXPORTS_OBJECT_REFERENCED;
|
74
|
+
const refs = [];
|
75
|
+
for (const referencedExport of this.referencedExports) {
|
76
|
+
if (
|
77
|
+
this._typePrefix === "import()" &&
|
78
|
+
referencedExport[0] === "default"
|
79
|
+
) {
|
80
|
+
const selfModule =
|
81
|
+
/** @type {ContextModule} */
|
82
|
+
(moduleGraph.getParentModule(this));
|
83
|
+
const importedModule =
|
84
|
+
/** @type {Module} */
|
85
|
+
(moduleGraph.getModule(this));
|
86
|
+
const exportsType = importedModule.getExportsType(
|
87
|
+
moduleGraph,
|
88
|
+
selfModule.options.namespaceObject === "strict"
|
89
|
+
);
|
90
|
+
if (
|
91
|
+
exportsType === "default-only" ||
|
92
|
+
exportsType === "default-with-named"
|
93
|
+
) {
|
94
|
+
return Dependency.EXPORTS_OBJECT_REFERENCED;
|
95
|
+
}
|
96
|
+
}
|
97
|
+
refs.push({
|
98
|
+
name: referencedExport,
|
99
|
+
canMangle: false
|
100
|
+
});
|
101
|
+
}
|
102
|
+
return refs;
|
76
103
|
}
|
77
104
|
|
78
105
|
/**
|