webpack 5.99.9 → 5.100.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/bin/webpack.js +8 -2
- package/hot/log.js +15 -15
- package/hot/poll.js +1 -0
- package/lib/APIPlugin.js +3 -3
- package/lib/AbstractMethodError.js +1 -0
- package/lib/AutomaticPrefetchPlugin.js +1 -0
- package/lib/BannerPlugin.js +1 -1
- package/lib/CaseSensitiveModulesWarning.js +4 -4
- package/lib/Chunk.js +6 -6
- package/lib/ChunkGraph.js +37 -31
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkTemplate.js +1 -1
- package/lib/CleanPlugin.js +94 -17
- package/lib/CodeGenerationResults.js +1 -1
- package/lib/CompatibilityPlugin.js +5 -2
- package/lib/Compilation.js +67 -45
- package/lib/Compiler.js +46 -16
- package/lib/ConcatenationScope.js +15 -6
- package/lib/ConstPlugin.js +5 -3
- package/lib/ContextModule.js +16 -12
- package/lib/ContextModuleFactory.js +4 -3
- package/lib/ContextReplacementPlugin.js +4 -2
- package/lib/CssModule.js +2 -2
- package/lib/DefinePlugin.js +111 -3
- package/lib/DelegatedModuleFactoryPlugin.js +18 -18
- package/lib/Dependency.js +6 -1
- package/lib/DependencyTemplate.js +1 -0
- package/lib/DllEntryPlugin.js +3 -1
- package/lib/DllPlugin.js +4 -3
- package/lib/DllReferencePlugin.js +2 -2
- package/lib/DynamicEntryPlugin.js +1 -1
- package/lib/EntryOptionPlugin.js +5 -0
- package/lib/ErrorHelpers.js +4 -4
- package/lib/EvalDevToolModulePlugin.js +3 -3
- package/lib/EvalSourceMapDevToolPlugin.js +7 -7
- package/lib/ExportsInfo.js +48 -39
- package/lib/ExternalModule.js +15 -11
- package/lib/ExternalModuleFactoryPlugin.js +5 -2
- package/lib/FileSystemInfo.js +51 -36
- package/lib/FlagDependencyExportsPlugin.js +14 -7
- package/lib/FlagDependencyUsagePlugin.js +1 -1
- package/lib/Generator.js +14 -1
- package/lib/HookWebpackError.js +1 -0
- package/lib/HotModuleReplacementPlugin.js +77 -50
- package/lib/IgnorePlugin.js +1 -1
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +0 -1
- package/lib/LibManifestPlugin.js +4 -2
- package/lib/LoaderOptionsPlugin.js +6 -4
- package/lib/MainTemplate.js +2 -2
- package/lib/Module.js +21 -6
- package/lib/ModuleFactory.js +1 -0
- package/lib/ModuleGraph.js +24 -2
- package/lib/ModuleGraphConnection.js +5 -5
- package/lib/ModuleInfoHeaderPlugin.js +2 -1
- package/lib/ModuleParseError.js +1 -0
- package/lib/ModuleSourceTypesConstants.js +12 -12
- package/lib/ModuleTemplate.js +1 -1
- package/lib/ModuleTypeConstants.js +21 -21
- package/lib/MultiCompiler.js +6 -6
- package/lib/NormalModule.js +31 -44
- package/lib/NormalModuleFactory.js +29 -19
- package/lib/NormalModuleReplacementPlugin.js +1 -1
- package/lib/NullFactory.js +1 -0
- package/lib/OptimizationStages.js +1 -1
- package/lib/Parser.js +1 -0
- package/lib/ProgressPlugin.js +12 -5
- package/lib/ProvidePlugin.js +5 -1
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/RuntimeGlobals.js +175 -155
- package/lib/RuntimeModule.js +1 -0
- package/lib/RuntimePlugin.js +33 -7
- package/lib/RuntimeTemplate.js +111 -11
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +15 -25
- package/lib/SourceMapDevToolPlugin.js +19 -17
- package/lib/Template.js +2 -2
- package/lib/TemplatedPathPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +7 -8
- package/lib/WatchIgnorePlugin.js +4 -3
- package/lib/WebpackIsIncludedPlugin.js +2 -1
- package/lib/WebpackOptionsApply.js +115 -27
- package/lib/asset/AssetGenerator.js +15 -11
- package/lib/asset/AssetModulesPlugin.js +19 -17
- package/lib/asset/AssetSourceGenerator.js +4 -4
- package/lib/asset/RawDataUrlModule.js +4 -2
- package/lib/async-modules/AwaitDependenciesInitFragment.js +1 -1
- package/lib/buildChunkGraph.js +6 -3
- package/lib/cache/AddBuildDependenciesPlugin.js +5 -6
- package/lib/cache/IdleFileCachePlugin.js +7 -4
- package/lib/cache/MemoryCachePlugin.js +1 -0
- package/lib/cache/MemoryWithGcCachePlugin.js +1 -0
- package/lib/cache/PackFileCacheStrategy.js +26 -20
- package/lib/cache/ResolverCachePlugin.js +16 -8
- package/lib/cli.js +15 -10
- package/lib/config/browserslistTargetHandler.js +3 -3
- package/lib/config/defaults.js +25 -17
- package/lib/config/normalization.js +2 -1
- package/lib/config/target.js +6 -5
- package/lib/container/ContainerPlugin.js +1 -1
- package/lib/container/ContainerReferencePlugin.js +1 -1
- package/lib/container/FallbackModule.js +2 -1
- package/lib/container/HoistContainerReferencesPlugin.js +1 -1
- package/lib/container/ModuleFederationPlugin.js +2 -2
- package/lib/container/RemoteModule.js +1 -1
- package/lib/css/CssGenerator.js +9 -6
- package/lib/css/CssModulesPlugin.js +44 -31
- package/lib/css/CssParser.js +6 -4
- package/lib/css/walkCssTokens.js +33 -37
- package/lib/debug/ProfilingPlugin.js +6 -6
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +8 -8
- package/lib/dependencies/AMDPlugin.js +12 -8
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +28 -26
- package/lib/dependencies/CachedConstDependency.js +1 -5
- package/lib/dependencies/CommonJsExportRequireDependency.js +6 -4
- package/lib/dependencies/CommonJsExportsParserPlugin.js +22 -25
- package/lib/dependencies/CommonJsFullRequireDependency.js +1 -9
- package/lib/dependencies/CommonJsImportsParserPlugin.js +100 -114
- package/lib/dependencies/CommonJsPlugin.js +15 -16
- package/lib/dependencies/ContextDependencyHelpers.js +2 -1
- package/lib/dependencies/ContextDependencyTemplateAsId.js +1 -0
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +1 -0
- package/lib/dependencies/CssIcssExportDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssSelfLocalIdentifierDependency.js +2 -1
- package/lib/dependencies/DynamicExports.js +9 -9
- package/lib/dependencies/ExportsInfoDependency.js +1 -1
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +122 -101
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +95 -19
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +11 -5
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +238 -162
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -1
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +20 -9
- package/lib/dependencies/HarmonyModulesPlugin.js +23 -12
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +1 -0
- package/lib/dependencies/ImportMetaContextPlugin.js +2 -1
- package/lib/dependencies/ImportMetaPlugin.js +2 -2
- package/lib/dependencies/ImportParserPlugin.js +40 -9
- package/lib/dependencies/ImportPlugin.js +3 -1
- package/lib/dependencies/LoaderPlugin.js +1 -0
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +1 -0
- package/lib/dependencies/RequireContextPlugin.js +3 -1
- package/lib/dependencies/RequireEnsurePlugin.js +6 -6
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +33 -34
- package/lib/dependencies/RequireIncludePlugin.js +1 -0
- package/lib/dependencies/RuntimeRequirementsDependency.js +1 -1
- package/lib/dependencies/SystemPlugin.js +1 -1
- package/lib/dependencies/URLContextDependency.js +65 -0
- package/lib/dependencies/URLPlugin.js +17 -157
- package/lib/dependencies/WorkerPlugin.js +23 -10
- package/lib/dependencies/processExportInfo.js +2 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +269 -185
- package/lib/esm/ModuleChunkLoadingPlugin.js +39 -1
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +70 -3
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/HotModuleReplacementRuntimeModule.js +1 -1
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +37 -0
- package/lib/hmr/LazyCompilationPlugin.js +4 -2
- package/lib/hmr/lazyCompilationBackend.js +4 -2
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -3
- package/lib/ids/DeterministicChunkIdsPlugin.js +30 -35
- package/lib/ids/DeterministicModuleIdsPlugin.js +4 -3
- package/lib/ids/HashedModuleIdsPlugin.js +5 -4
- package/lib/ids/IdHelpers.js +21 -17
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +4 -4
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -1
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +3 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +1 -1
- package/lib/ids/SyncModuleIdsPlugin.js +1 -1
- package/lib/index.js +13 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +113 -119
- package/lib/javascript/BasicEvaluatedExpression.js +2 -1
- package/lib/javascript/ChunkHelpers.js +1 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +121 -136
- package/lib/javascript/EnableChunkLoadingPlugin.js +6 -3
- package/lib/javascript/JavascriptGenerator.js +14 -2
- package/lib/javascript/JavascriptModulesPlugin.js +68 -27
- package/lib/javascript/JavascriptParser.js +117 -76
- package/lib/javascript/JavascriptParserHelpers.js +41 -41
- package/lib/javascript/StartupHelpers.js +17 -17
- package/lib/json/JsonGenerator.js +4 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/json/JsonParser.js +1 -1
- package/lib/library/AbstractLibraryPlugin.js +6 -2
- package/lib/library/AssignLibraryPlugin.js +21 -6
- package/lib/library/EnableLibraryPlugin.js +23 -3
- package/lib/library/UmdLibraryPlugin.js +15 -6
- package/lib/logging/createConsoleLogger.js +3 -3
- package/lib/logging/runtime.js +9 -9
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/RequireChunkLoadingRuntimeModule.js +4 -22
- package/lib/node/nodeConsole.js +4 -2
- package/lib/optimize/AggressiveMergingPlugin.js +45 -46
- package/lib/optimize/AggressiveSplittingPlugin.js +13 -12
- package/lib/optimize/ConcatenatedModule.js +227 -57
- package/lib/optimize/EnsureChunkConditionsPlugin.js +58 -58
- package/lib/optimize/FlagIncludedChunksPlugin.js +3 -1
- package/lib/optimize/InnerGraph.js +115 -112
- package/lib/optimize/InnerGraphPlugin.js +2 -2
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +4 -3
- package/lib/optimize/MergeDuplicateChunksPlugin.js +80 -81
- package/lib/optimize/MinChunkSizePlugin.js +6 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +31 -22
- package/lib/optimize/RealContentHashPlugin.js +26 -20
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -1
- package/lib/optimize/RemoveParentModulesPlugin.js +1 -0
- package/lib/optimize/SideEffectsFlagPlugin.js +3 -2
- package/lib/optimize/SplitChunksPlugin.js +16 -13
- package/lib/rules/BasicEffectRulePlugin.js +4 -2
- package/lib/rules/BasicMatcherRulePlugin.js +3 -1
- package/lib/rules/ObjectMatcherRulePlugin.js +3 -1
- package/lib/rules/RuleSetCompiler.js +6 -3
- package/lib/rules/UseEffectRulePlugin.js +3 -1
- package/lib/runtime/AsyncModuleRuntimeModule.js +64 -9
- package/lib/runtime/CreateFakeNamespaceObjectRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +214 -0
- package/lib/runtime/RuntimeIdRuntimeModule.js +2 -1
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +8 -7
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +27 -19
- package/lib/schemes/VirtualUrlPlugin.js +222 -0
- package/lib/serialization/AggregateErrorSerializer.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +5 -4
- package/lib/serialization/FileMiddleware.js +7 -4
- package/lib/serialization/ObjectMiddleware.js +14 -8
- package/lib/serialization/Serializer.js +5 -3
- package/lib/serialization/SerializerMiddleware.js +2 -0
- package/lib/sharing/ConsumeSharedModule.js +1 -1
- package/lib/sharing/ConsumeSharedPlugin.js +3 -3
- package/lib/sharing/ConsumeSharedRuntimeModule.js +2 -2
- package/lib/sharing/ProvideSharedModule.js +1 -1
- package/lib/sharing/ProvideSharedPlugin.js +3 -2
- package/lib/sharing/SharePlugin.js +2 -1
- package/lib/sharing/ShareRuntimeModule.js +3 -5
- package/lib/sharing/utils.js +34 -34
- package/lib/stats/DefaultStatsFactoryPlugin.js +49 -46
- package/lib/stats/DefaultStatsPresetPlugin.js +4 -2
- package/lib/stats/DefaultStatsPrinterPlugin.js +15 -9
- package/lib/stats/StatsFactory.js +4 -2
- package/lib/stats/StatsPrinter.js +3 -2
- package/lib/url/URLParserPlugin.js +266 -0
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/Hash.js +2 -0
- package/lib/util/IterableHelpers.js +1 -1
- package/lib/util/LazyBucketSortedSet.js +2 -1
- package/lib/util/LazySet.js +11 -6
- package/lib/util/ParallelismFactorCalculator.js +1 -1
- package/lib/util/SetHelpers.js +3 -3
- package/lib/util/SortableSet.js +2 -2
- package/lib/util/StackedCacheMap.js +3 -1
- package/lib/util/StackedMap.js +2 -2
- package/lib/util/StringXor.js +1 -0
- package/lib/util/TupleSet.js +1 -0
- package/lib/util/URLAbsoluteSpecifier.js +1 -1
- package/lib/util/cleverMerge.js +12 -8
- package/lib/util/comparators.js +154 -127
- package/lib/util/compileBooleanMatcher.js +8 -3
- package/lib/util/concatenate.js +8 -7
- package/lib/util/conventions.js +72 -73
- package/lib/util/create-schema-validation.js +2 -1
- package/lib/util/createHash.js +10 -4
- package/lib/util/deprecation.js +69 -66
- package/lib/util/deterministicGrouping.js +4 -2
- package/lib/util/extractUrlAndGlobal.js +1 -1
- package/lib/util/findGraphRoots.js +2 -2
- package/lib/util/fs.js +30 -23
- package/lib/util/hash/md4.js +2 -2
- package/lib/util/hash/wasm-hash.js +4 -2
- package/lib/util/identifier.js +13 -12
- package/lib/util/internalSerializables.js +2 -0
- package/lib/util/magicComment.js +5 -5
- package/lib/util/processAsyncTree.js +1 -1
- package/lib/util/propertyAccess.js +1 -1
- package/lib/util/propertyName.js +1 -1
- package/lib/util/registerExternalSerializer.js +1 -2
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +29 -21
- package/lib/util/semver.js +1 -1
- package/lib/util/serialization.js +3 -0
- package/lib/util/source.js +3 -2
- package/lib/validateSchema.js +1 -0
- package/lib/wasm/EnableWasmLoadingPlugin.js +6 -3
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +4 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +46 -49
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +2 -3
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +3 -2
- package/lib/wasm-sync/WebAssemblyJavascriptGenerator.js +3 -0
- package/lib/wasm-sync/WebAssemblyUtils.js +1 -1
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +4 -22
- package/lib/webpack.js +4 -5
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +1 -0
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +6 -24
- package/lib/webworker/WebWorkerTemplatePlugin.js +1 -0
- package/package.json +119 -113
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +17 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.d.ts +7 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.check.js +6 -0
- package/schemas/plugins/schemes/VirtualUrlPlugin.json +77 -0
- package/types.d.ts +1230 -360
|
@@ -11,6 +11,8 @@ const { STAGE_BASIC } = require("../OptimizationStages");
|
|
|
11
11
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
|
12
12
|
/** @typedef {import("../Compiler")} Compiler */
|
|
13
13
|
|
|
14
|
+
const PLUGIN_NAME = "EnsureChunkConditionsPlugin";
|
|
15
|
+
|
|
14
16
|
class EnsureChunkConditionsPlugin {
|
|
15
17
|
/**
|
|
16
18
|
* Apply the plugin
|
|
@@ -18,71 +20,69 @@ class EnsureChunkConditionsPlugin {
|
|
|
18
20
|
* @returns {void}
|
|
19
21
|
*/
|
|
20
22
|
apply(compiler) {
|
|
21
|
-
compiler.hooks.compilation.tap(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
for (const
|
|
36
|
-
if (!module.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
for (const group of chunk.groupsIterable) {
|
|
41
|
-
chunkGroups.add(group);
|
|
42
|
-
}
|
|
23
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
|
24
|
+
/**
|
|
25
|
+
* @param {Iterable<Chunk>} chunks the chunks
|
|
26
|
+
*/
|
|
27
|
+
const handler = chunks => {
|
|
28
|
+
const chunkGraph = compilation.chunkGraph;
|
|
29
|
+
// These sets are hoisted here to save memory
|
|
30
|
+
// They are cleared at the end of every loop
|
|
31
|
+
/** @type {Set<Chunk>} */
|
|
32
|
+
const sourceChunks = new Set();
|
|
33
|
+
/** @type {Set<ChunkGroup>} */
|
|
34
|
+
const chunkGroups = new Set();
|
|
35
|
+
for (const module of compilation.modules) {
|
|
36
|
+
if (!module.hasChunkCondition()) continue;
|
|
37
|
+
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
|
38
|
+
if (!module.chunkCondition(chunk, compilation)) {
|
|
39
|
+
sourceChunks.add(chunk);
|
|
40
|
+
for (const group of chunk.groupsIterable) {
|
|
41
|
+
chunkGroups.add(group);
|
|
43
42
|
}
|
|
44
43
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
// We reached the entrypoint: fail
|
|
57
|
-
if (chunkGroup.isInitial()) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`Cannot fulfil chunk condition of ${module.identifier()}`
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
// Try placing in all parents
|
|
63
|
-
for (const group of chunkGroup.parentsIterable) {
|
|
64
|
-
chunkGroups.add(group);
|
|
44
|
+
}
|
|
45
|
+
if (sourceChunks.size === 0) continue;
|
|
46
|
+
/** @type {Set<Chunk>} */
|
|
47
|
+
const targetChunks = new Set();
|
|
48
|
+
chunkGroupLoop: for (const chunkGroup of chunkGroups) {
|
|
49
|
+
// Can module be placed in a chunk of this group?
|
|
50
|
+
for (const chunk of chunkGroup.chunks) {
|
|
51
|
+
if (module.chunkCondition(chunk, compilation)) {
|
|
52
|
+
targetChunks.add(chunk);
|
|
53
|
+
continue chunkGroupLoop;
|
|
65
54
|
}
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
// We reached the entrypoint: fail
|
|
57
|
+
if (chunkGroup.isInitial()) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`Cannot fulfil chunk condition of ${module.identifier()}`
|
|
60
|
+
);
|
|
69
61
|
}
|
|
70
|
-
|
|
71
|
-
|
|
62
|
+
// Try placing in all parents
|
|
63
|
+
for (const group of chunkGroup.parentsIterable) {
|
|
64
|
+
chunkGroups.add(group);
|
|
72
65
|
}
|
|
73
|
-
sourceChunks.clear();
|
|
74
|
-
chunkGroups.clear();
|
|
75
66
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
67
|
+
for (const sourceChunk of sourceChunks) {
|
|
68
|
+
chunkGraph.disconnectChunkAndModule(sourceChunk, module);
|
|
69
|
+
}
|
|
70
|
+
for (const targetChunk of targetChunks) {
|
|
71
|
+
chunkGraph.connectChunkAndModule(targetChunk, module);
|
|
72
|
+
}
|
|
73
|
+
sourceChunks.clear();
|
|
74
|
+
chunkGroups.clear();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
compilation.hooks.optimizeChunks.tap(
|
|
78
|
+
{
|
|
79
|
+
name: PLUGIN_NAME,
|
|
80
|
+
stage: STAGE_BASIC
|
|
81
|
+
},
|
|
82
|
+
handler
|
|
83
|
+
);
|
|
84
|
+
});
|
|
86
85
|
}
|
|
87
86
|
}
|
|
87
|
+
|
|
88
88
|
module.exports = EnsureChunkConditionsPlugin;
|
|
@@ -78,8 +78,9 @@ class FlagIncludedChunksPlugin {
|
|
|
78
78
|
bestModule === undefined ||
|
|
79
79
|
chunkGraph.getNumberOfModuleChunks(bestModule) >
|
|
80
80
|
chunkGraph.getNumberOfModuleChunks(module)
|
|
81
|
-
)
|
|
81
|
+
) {
|
|
82
82
|
bestModule = module;
|
|
83
|
+
}
|
|
83
84
|
}
|
|
84
85
|
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
|
|
85
86
|
/** @type {Module} */ (bestModule)
|
|
@@ -122,4 +123,5 @@ class FlagIncludedChunksPlugin {
|
|
|
122
123
|
});
|
|
123
124
|
}
|
|
124
125
|
}
|
|
126
|
+
|
|
125
127
|
module.exports = FlagIncludedChunksPlugin;
|
|
@@ -30,6 +30,17 @@ const { UsageState } = require("../ExportsInfo");
|
|
|
30
30
|
|
|
31
31
|
/** @typedef {false|StateObject} State */
|
|
32
32
|
|
|
33
|
+
class TopLevelSymbol {
|
|
34
|
+
/**
|
|
35
|
+
* @param {string} name name of the variable
|
|
36
|
+
*/
|
|
37
|
+
constructor(name) {
|
|
38
|
+
this.name = name;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
module.exports.TopLevelSymbol = TopLevelSymbol;
|
|
43
|
+
|
|
33
44
|
/** @type {WeakMap<ParserState, State>} */
|
|
34
45
|
const parserStateMap = new WeakMap();
|
|
35
46
|
const topLevelSymbolTag = Symbol("top level symbol");
|
|
@@ -42,39 +53,6 @@ function getState(parserState) {
|
|
|
42
53
|
return parserStateMap.get(parserState);
|
|
43
54
|
}
|
|
44
55
|
|
|
45
|
-
/**
|
|
46
|
-
* @param {ParserState} parserState parser state
|
|
47
|
-
* @returns {void}
|
|
48
|
-
*/
|
|
49
|
-
module.exports.bailout = parserState => {
|
|
50
|
-
parserStateMap.set(parserState, false);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @param {ParserState} parserState parser state
|
|
55
|
-
* @returns {void}
|
|
56
|
-
*/
|
|
57
|
-
module.exports.enable = parserState => {
|
|
58
|
-
const state = parserStateMap.get(parserState);
|
|
59
|
-
if (state === false) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
parserStateMap.set(parserState, {
|
|
63
|
-
innerGraph: new Map(),
|
|
64
|
-
currentTopLevelSymbol: undefined,
|
|
65
|
-
usageCallbackMap: new Map()
|
|
66
|
-
});
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @param {ParserState} parserState parser state
|
|
71
|
-
* @returns {boolean} true, when enabled
|
|
72
|
-
*/
|
|
73
|
-
module.exports.isEnabled = parserState => {
|
|
74
|
-
const state = parserStateMap.get(parserState);
|
|
75
|
-
return Boolean(state);
|
|
76
|
-
};
|
|
77
|
-
|
|
78
56
|
/**
|
|
79
57
|
* @param {ParserState} state parser state
|
|
80
58
|
* @param {TopLevelSymbol | null} symbol the symbol, or null for all symbols
|
|
@@ -113,6 +91,71 @@ module.exports.addVariableUsage = (parser, name, usage) => {
|
|
|
113
91
|
}
|
|
114
92
|
};
|
|
115
93
|
|
|
94
|
+
/**
|
|
95
|
+
* @param {ParserState} parserState parser state
|
|
96
|
+
* @returns {void}
|
|
97
|
+
*/
|
|
98
|
+
module.exports.bailout = parserState => {
|
|
99
|
+
parserStateMap.set(parserState, false);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @param {ParserState} parserState parser state
|
|
104
|
+
* @returns {void}
|
|
105
|
+
*/
|
|
106
|
+
module.exports.enable = parserState => {
|
|
107
|
+
const state = parserStateMap.get(parserState);
|
|
108
|
+
if (state === false) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
parserStateMap.set(parserState, {
|
|
112
|
+
innerGraph: new Map(),
|
|
113
|
+
currentTopLevelSymbol: undefined,
|
|
114
|
+
usageCallbackMap: new Map()
|
|
115
|
+
});
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @param {Dependency} dependency the dependency
|
|
120
|
+
* @param {Set<string> | boolean | undefined} usedByExports usedByExports info
|
|
121
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
122
|
+
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
123
|
+
*/
|
|
124
|
+
module.exports.getDependencyUsedByExportsCondition = (
|
|
125
|
+
dependency,
|
|
126
|
+
usedByExports,
|
|
127
|
+
moduleGraph
|
|
128
|
+
) => {
|
|
129
|
+
if (usedByExports === false) return false;
|
|
130
|
+
if (usedByExports !== true && usedByExports !== undefined) {
|
|
131
|
+
const selfModule =
|
|
132
|
+
/** @type {Module} */
|
|
133
|
+
(moduleGraph.getParentModule(dependency));
|
|
134
|
+
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
135
|
+
return (connections, runtime) => {
|
|
136
|
+
for (const exportName of usedByExports) {
|
|
137
|
+
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* @param {ParserState} state parser state
|
|
149
|
+
* @returns {TopLevelSymbol|void} usage data
|
|
150
|
+
*/
|
|
151
|
+
module.exports.getTopLevelSymbol = state => {
|
|
152
|
+
const innerGraphState = getState(state);
|
|
153
|
+
|
|
154
|
+
if (innerGraphState) {
|
|
155
|
+
return innerGraphState.currentTopLevelSymbol;
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
|
|
116
159
|
/**
|
|
117
160
|
* @param {ParserState} state parser state
|
|
118
161
|
* @returns {void}
|
|
@@ -209,6 +252,45 @@ module.exports.inferDependencyUsage = state => {
|
|
|
209
252
|
}
|
|
210
253
|
};
|
|
211
254
|
|
|
255
|
+
/**
|
|
256
|
+
* @param {Dependency} dependency the dependency
|
|
257
|
+
* @param {Set<string> | boolean} usedByExports usedByExports info
|
|
258
|
+
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
259
|
+
* @param {RuntimeSpec} runtime runtime
|
|
260
|
+
* @returns {boolean} false, when unused. Otherwise true
|
|
261
|
+
*/
|
|
262
|
+
module.exports.isDependencyUsedByExports = (
|
|
263
|
+
dependency,
|
|
264
|
+
usedByExports,
|
|
265
|
+
moduleGraph,
|
|
266
|
+
runtime
|
|
267
|
+
) => {
|
|
268
|
+
if (usedByExports === false) return false;
|
|
269
|
+
if (usedByExports !== true && usedByExports !== undefined) {
|
|
270
|
+
const selfModule =
|
|
271
|
+
/** @type {Module} */
|
|
272
|
+
(moduleGraph.getParentModule(dependency));
|
|
273
|
+
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
274
|
+
let used = false;
|
|
275
|
+
for (const exportName of usedByExports) {
|
|
276
|
+
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused) {
|
|
277
|
+
used = true;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
if (!used) return false;
|
|
281
|
+
}
|
|
282
|
+
return true;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* @param {ParserState} parserState parser state
|
|
287
|
+
* @returns {boolean} true, when enabled
|
|
288
|
+
*/
|
|
289
|
+
module.exports.isEnabled = parserState => {
|
|
290
|
+
const state = parserStateMap.get(parserState);
|
|
291
|
+
return Boolean(state);
|
|
292
|
+
};
|
|
293
|
+
|
|
212
294
|
/**
|
|
213
295
|
* @param {ParserState} state parser state
|
|
214
296
|
* @param {UsageCallback} onUsageCallback on usage callback
|
|
@@ -247,18 +329,6 @@ module.exports.setTopLevelSymbol = (state, symbol) => {
|
|
|
247
329
|
}
|
|
248
330
|
};
|
|
249
331
|
|
|
250
|
-
/**
|
|
251
|
-
* @param {ParserState} state parser state
|
|
252
|
-
* @returns {TopLevelSymbol|void} usage data
|
|
253
|
-
*/
|
|
254
|
-
module.exports.getTopLevelSymbol = state => {
|
|
255
|
-
const innerGraphState = getState(state);
|
|
256
|
-
|
|
257
|
-
if (innerGraphState) {
|
|
258
|
-
return innerGraphState.currentTopLevelSymbol;
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
|
|
262
332
|
/**
|
|
263
333
|
* @param {JavascriptParser} parser parser
|
|
264
334
|
* @param {string} name name of variable
|
|
@@ -282,71 +352,4 @@ module.exports.tagTopLevelSymbol = (parser, name) => {
|
|
|
282
352
|
return fn;
|
|
283
353
|
};
|
|
284
354
|
|
|
285
|
-
/**
|
|
286
|
-
* @param {Dependency} dependency the dependency
|
|
287
|
-
* @param {Set<string> | boolean} usedByExports usedByExports info
|
|
288
|
-
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
289
|
-
* @param {RuntimeSpec} runtime runtime
|
|
290
|
-
* @returns {boolean} false, when unused. Otherwise true
|
|
291
|
-
*/
|
|
292
|
-
module.exports.isDependencyUsedByExports = (
|
|
293
|
-
dependency,
|
|
294
|
-
usedByExports,
|
|
295
|
-
moduleGraph,
|
|
296
|
-
runtime
|
|
297
|
-
) => {
|
|
298
|
-
if (usedByExports === false) return false;
|
|
299
|
-
if (usedByExports !== true && usedByExports !== undefined) {
|
|
300
|
-
const selfModule =
|
|
301
|
-
/** @type {Module} */
|
|
302
|
-
(moduleGraph.getParentModule(dependency));
|
|
303
|
-
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
304
|
-
let used = false;
|
|
305
|
-
for (const exportName of usedByExports) {
|
|
306
|
-
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused)
|
|
307
|
-
used = true;
|
|
308
|
-
}
|
|
309
|
-
if (!used) return false;
|
|
310
|
-
}
|
|
311
|
-
return true;
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* @param {Dependency} dependency the dependency
|
|
316
|
-
* @param {Set<string> | boolean | undefined} usedByExports usedByExports info
|
|
317
|
-
* @param {ModuleGraph} moduleGraph moduleGraph
|
|
318
|
-
* @returns {null | false | GetConditionFn} function to determine if the connection is active
|
|
319
|
-
*/
|
|
320
|
-
module.exports.getDependencyUsedByExportsCondition = (
|
|
321
|
-
dependency,
|
|
322
|
-
usedByExports,
|
|
323
|
-
moduleGraph
|
|
324
|
-
) => {
|
|
325
|
-
if (usedByExports === false) return false;
|
|
326
|
-
if (usedByExports !== true && usedByExports !== undefined) {
|
|
327
|
-
const selfModule =
|
|
328
|
-
/** @type {Module} */
|
|
329
|
-
(moduleGraph.getParentModule(dependency));
|
|
330
|
-
const exportsInfo = moduleGraph.getExportsInfo(selfModule);
|
|
331
|
-
return (connections, runtime) => {
|
|
332
|
-
for (const exportName of usedByExports) {
|
|
333
|
-
if (exportsInfo.getUsed(exportName, runtime) !== UsageState.Unused)
|
|
334
|
-
return true;
|
|
335
|
-
}
|
|
336
|
-
return false;
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
return null;
|
|
340
|
-
};
|
|
341
|
-
|
|
342
|
-
class TopLevelSymbol {
|
|
343
|
-
/**
|
|
344
|
-
* @param {string} name name of the variable
|
|
345
|
-
*/
|
|
346
|
-
constructor(name) {
|
|
347
|
-
this.name = name;
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
module.exports.TopLevelSymbol = TopLevelSymbol;
|
|
352
355
|
module.exports.topLevelSymbolTag = topLevelSymbolTag;
|
|
@@ -195,7 +195,7 @@ class InnerGraphPlugin {
|
|
|
195
195
|
}
|
|
196
196
|
});
|
|
197
197
|
|
|
198
|
-
parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl,
|
|
198
|
+
parser.hooks.preDeclarator.tap(PLUGIN_NAME, (decl, _statement) => {
|
|
199
199
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
200
200
|
if (
|
|
201
201
|
parser.scope.topLevelScope === true &&
|
|
@@ -363,7 +363,7 @@ class InnerGraphPlugin {
|
|
|
363
363
|
}
|
|
364
364
|
);
|
|
365
365
|
|
|
366
|
-
parser.hooks.declarator.tap(PLUGIN_NAME, (decl,
|
|
366
|
+
parser.hooks.declarator.tap(PLUGIN_NAME, (decl, _statement) => {
|
|
367
367
|
if (!InnerGraph.isEnabled(parser.state)) return;
|
|
368
368
|
const fn = declWithTopLevelSymbol.get(decl);
|
|
369
369
|
|
|
@@ -15,7 +15,7 @@ const createSchemaValidation = require("../util/create-schema-validation");
|
|
|
15
15
|
/** @typedef {import("../Compiler")} Compiler */
|
|
16
16
|
|
|
17
17
|
const validate = createSchemaValidation(
|
|
18
|
-
require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check
|
|
18
|
+
require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check"),
|
|
19
19
|
() => require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
|
|
20
20
|
{
|
|
21
21
|
name: "Limit Chunk Count Plugin",
|
|
@@ -85,7 +85,8 @@ class LimitChunkCountPlugin {
|
|
|
85
85
|
|
|
86
86
|
// order chunks in a deterministic way
|
|
87
87
|
const compareChunksWithGraph = compareChunks(chunkGraph);
|
|
88
|
-
|
|
88
|
+
/** @type {Chunk[]} */
|
|
89
|
+
const orderedChunks = [...chunks].sort(compareChunksWithGraph);
|
|
89
90
|
|
|
90
91
|
// create a lazy sorted data structure to keep all combinations
|
|
91
92
|
// this is large. Size = chunks * (chunks - 1) / 2
|
|
@@ -296,4 +297,5 @@ class LimitChunkCountPlugin {
|
|
|
296
297
|
});
|
|
297
298
|
}
|
|
298
299
|
}
|
|
300
|
+
|
|
299
301
|
module.exports = LimitChunkCountPlugin;
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
|
|
8
8
|
const { UsageState } = require("../ExportsInfo");
|
|
9
9
|
const {
|
|
10
|
-
|
|
10
|
+
NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS,
|
|
11
11
|
NUMBER_OF_IDENTIFIER_START_CHARS,
|
|
12
|
-
|
|
12
|
+
numberToIdentifier
|
|
13
13
|
} = require("../Template");
|
|
14
14
|
const { assignDeterministicIds } = require("../ids/IdHelpers");
|
|
15
15
|
const { compareSelect, compareStringsNumeric } = require("../util/comparators");
|
|
@@ -23,8 +23,9 @@ const { compareSelect, compareStringsNumeric } = require("../util/comparators");
|
|
|
23
23
|
* @returns {boolean} mangle is possible
|
|
24
24
|
*/
|
|
25
25
|
const canMangle = exportsInfo => {
|
|
26
|
-
if (exportsInfo.otherExportsInfo.getUsed(undefined) !== UsageState.Unused)
|
|
26
|
+
if (exportsInfo.otherExportsInfo.getUsed(undefined) !== UsageState.Unused) {
|
|
27
27
|
return false;
|
|
28
|
+
}
|
|
28
29
|
let hasSomethingToMangle = false;
|
|
29
30
|
for (const exportInfo of exportsInfo.exports) {
|
|
30
31
|
if (exportInfo.canMangle === true) {
|
|
@@ -13,7 +13,7 @@ const { runtimeEqual } = require("../util/runtime");
|
|
|
13
13
|
/** @typedef {import("../Compiler")} Compiler */
|
|
14
14
|
|
|
15
15
|
const validate = createSchemaValidation(
|
|
16
|
-
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check
|
|
16
|
+
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check"),
|
|
17
17
|
() =>
|
|
18
18
|
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.json"),
|
|
19
19
|
{
|
|
@@ -22,6 +22,8 @@ const validate = createSchemaValidation(
|
|
|
22
22
|
}
|
|
23
23
|
);
|
|
24
24
|
|
|
25
|
+
const PLUGIN_NAME = "MergeDuplicateChunksPlugin";
|
|
26
|
+
|
|
25
27
|
class MergeDuplicateChunksPlugin {
|
|
26
28
|
/**
|
|
27
29
|
* @param {MergeDuplicateChunksPluginOptions} options options object
|
|
@@ -36,100 +38,97 @@ class MergeDuplicateChunksPlugin {
|
|
|
36
38
|
* @returns {void}
|
|
37
39
|
*/
|
|
38
40
|
apply(compiler) {
|
|
39
|
-
compiler.hooks.compilation.tap(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
chunks => {
|
|
48
|
-
const { chunkGraph, moduleGraph } = compilation;
|
|
41
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
|
42
|
+
compilation.hooks.optimizeChunks.tap(
|
|
43
|
+
{
|
|
44
|
+
name: PLUGIN_NAME,
|
|
45
|
+
stage: this.options.stage
|
|
46
|
+
},
|
|
47
|
+
chunks => {
|
|
48
|
+
const { chunkGraph, moduleGraph } = compilation;
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
// remember already tested chunks for performance
|
|
51
|
+
const notDuplicates = new Set();
|
|
52
52
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
dup
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
) {
|
|
71
|
-
|
|
72
|
-
if (possibleDuplicates === undefined) {
|
|
73
|
-
possibleDuplicates = new Set();
|
|
74
|
-
}
|
|
75
|
-
possibleDuplicates.add(dup);
|
|
53
|
+
// for each chunk
|
|
54
|
+
for (const chunk of chunks) {
|
|
55
|
+
// track a Set of all chunk that could be duplicates
|
|
56
|
+
let possibleDuplicates;
|
|
57
|
+
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
|
58
|
+
if (possibleDuplicates === undefined) {
|
|
59
|
+
// when possibleDuplicates is not yet set,
|
|
60
|
+
// create a new Set from chunks of the current module
|
|
61
|
+
// including only chunks with the same number of modules
|
|
62
|
+
for (const dup of chunkGraph.getModuleChunksIterable(module)) {
|
|
63
|
+
if (
|
|
64
|
+
dup !== chunk &&
|
|
65
|
+
chunkGraph.getNumberOfChunkModules(chunk) ===
|
|
66
|
+
chunkGraph.getNumberOfChunkModules(dup) &&
|
|
67
|
+
!notDuplicates.has(dup)
|
|
68
|
+
) {
|
|
69
|
+
// delay allocating the new Set until here, reduce memory pressure
|
|
70
|
+
if (possibleDuplicates === undefined) {
|
|
71
|
+
possibleDuplicates = new Set();
|
|
76
72
|
}
|
|
73
|
+
possibleDuplicates.add(dup);
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
75
|
+
}
|
|
76
|
+
// when no chunk is possible we can break here
|
|
77
|
+
if (possibleDuplicates === undefined) break;
|
|
78
|
+
} else {
|
|
79
|
+
// validate existing possible duplicates
|
|
80
|
+
for (const dup of possibleDuplicates) {
|
|
81
|
+
// remove possible duplicate when module is not contained
|
|
82
|
+
if (!chunkGraph.isModuleInChunk(module, dup)) {
|
|
83
|
+
possibleDuplicates.delete(dup);
|
|
87
84
|
}
|
|
88
|
-
// when all chunks has been removed we can break here
|
|
89
|
-
if (possibleDuplicates.size === 0) break;
|
|
90
85
|
}
|
|
86
|
+
// when all chunks has been removed we can break here
|
|
87
|
+
if (possibleDuplicates.size === 0) break;
|
|
91
88
|
}
|
|
89
|
+
}
|
|
92
90
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
|
|
91
|
+
// when we found duplicates
|
|
92
|
+
if (
|
|
93
|
+
possibleDuplicates !== undefined &&
|
|
94
|
+
possibleDuplicates.size > 0
|
|
95
|
+
) {
|
|
96
|
+
outer: for (const otherChunk of possibleDuplicates) {
|
|
97
|
+
if (otherChunk.hasRuntime() !== chunk.hasRuntime()) continue;
|
|
98
|
+
if (chunkGraph.getNumberOfEntryModules(chunk) > 0) continue;
|
|
99
|
+
if (chunkGraph.getNumberOfEntryModules(otherChunk) > 0) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (!runtimeEqual(chunk.runtime, otherChunk.runtime)) {
|
|
103
|
+
for (const module of chunkGraph.getChunkModulesIterable(
|
|
104
|
+
chunk
|
|
105
|
+
)) {
|
|
106
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
|
107
|
+
if (
|
|
108
|
+
!exportsInfo.isEquallyUsed(
|
|
109
|
+
chunk.runtime,
|
|
110
|
+
otherChunk.runtime
|
|
111
|
+
)
|
|
112
|
+
) {
|
|
113
|
+
continue outer;
|
|
116
114
|
}
|
|
117
115
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
}
|
|
117
|
+
// merge them
|
|
118
|
+
if (chunkGraph.canChunksBeIntegrated(chunk, otherChunk)) {
|
|
119
|
+
chunkGraph.integrateChunks(chunk, otherChunk);
|
|
120
|
+
compilation.chunks.delete(otherChunk);
|
|
123
121
|
}
|
|
124
122
|
}
|
|
125
|
-
|
|
126
|
-
// don't check already processed chunks twice
|
|
127
|
-
notDuplicates.add(chunk);
|
|
128
123
|
}
|
|
124
|
+
|
|
125
|
+
// don't check already processed chunks twice
|
|
126
|
+
notDuplicates.add(chunk);
|
|
129
127
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
});
|
|
133
131
|
}
|
|
134
132
|
}
|
|
133
|
+
|
|
135
134
|
module.exports = MergeDuplicateChunksPlugin;
|