webpack 5.99.6 → 5.99.8
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/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +21 -15
- package/lib/Compiler.js +2 -1
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +1 -1
- package/lib/ContextModuleFactory.js +1 -2
- package/lib/ContextReplacementPlugin.js +7 -4
- package/lib/DefinePlugin.js +2 -2
- package/lib/DelegatedModule.js +18 -8
- package/lib/DelegatedModuleFactoryPlugin.js +9 -7
- package/lib/DelegatedPlugin.js +4 -2
- package/lib/DllEntryPlugin.js +4 -2
- package/lib/DllPlugin.js +5 -3
- package/lib/DllReferencePlugin.js +56 -60
- package/lib/DynamicEntryPlugin.js +4 -2
- package/lib/EntryOptionPlugin.js +3 -1
- package/lib/EntryPlugin.js +4 -2
- package/lib/EnvironmentPlugin.js +4 -2
- package/lib/EvalDevToolModulePlugin.js +9 -7
- package/lib/EvalSourceMapDevToolPlugin.js +138 -139
- package/lib/ExportsInfo.js +35 -16
- package/lib/ExternalModule.js +6 -5
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FileSystemInfo.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +5 -6
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +19 -12
- package/lib/ModuleFilenameHelpers.js +8 -4
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +13 -8
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +4 -2
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +72 -102
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +9 -8
- package/lib/WarnCaseSensitiveModulesPlugin.js +36 -37
- package/lib/WarnNoModeSetPlugin.js +3 -1
- package/lib/WatchIgnorePlugin.js +3 -1
- package/lib/WebpackError.js +11 -3
- package/lib/WebpackOptionsApply.js +6 -7
- package/lib/asset/AssetGenerator.js +2 -2
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/cache/IdleFileCachePlugin.js +11 -12
- package/lib/cache/MemoryWithGcCachePlugin.js +7 -5
- package/lib/cache/ResolverCachePlugin.js +8 -6
- package/lib/cli.js +5 -1
- package/lib/config/defaults.js +10 -6
- package/lib/config/normalization.js +14 -8
- package/lib/container/ContainerReferencePlugin.js +24 -26
- package/lib/container/ModuleFederationPlugin.js +2 -1
- package/lib/css/CssGenerator.js +1 -1
- package/lib/css/CssModulesPlugin.js +8 -6
- package/lib/debug/ProfilingPlugin.js +18 -21
- package/lib/dependencies/CommonJsImportsParserPlugin.js +1 -1
- package/lib/dependencies/ContextElementDependency.js +1 -1
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireContextPlugin.js +2 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +72 -73
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -2
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicModuleIdsPlugin.js +47 -48
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +4 -2
- package/lib/ids/NamedModuleIdsPlugin.js +4 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +4 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceChunkIdsPlugin.js +4 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -2
- package/lib/index.js +11 -0
- package/lib/javascript/JavascriptModulesPlugin.js +2 -2
- package/lib/javascript/JavascriptParser.js +634 -656
- package/lib/json/JsonModulesPlugin.js +4 -4
- package/lib/library/AbstractLibraryPlugin.js +1 -1
- package/lib/library/ModuleLibraryPlugin.js +60 -42
- package/lib/node/CommonJsChunkLoadingPlugin.js +69 -73
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/nodeConsole.js +3 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +15 -16
- package/lib/optimize/FlagIncludedChunksPlugin.js +92 -97
- package/lib/optimize/LimitChunkCountPlugin.js +4 -2
- package/lib/optimize/MangleExportsPlugin.js +15 -16
- package/lib/optimize/MinChunkSizePlugin.js +4 -2
- package/lib/optimize/ModuleConcatenationPlugin.js +6 -4
- package/lib/optimize/RealContentHashPlugin.js +4 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +5 -3
- package/lib/optimize/RemoveParentModulesPlugin.js +4 -2
- package/lib/optimize/RuntimeChunkPlugin.js +21 -23
- package/lib/optimize/SideEffectsFlagPlugin.js +9 -6
- package/lib/optimize/SplitChunksPlugin.js +9 -7
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/rules/BasicEffectRulePlugin.js +1 -2
- package/lib/rules/ObjectMatcherRulePlugin.js +2 -1
- package/lib/rules/RuleSetCompiler.js +19 -5
- package/lib/rules/UseEffectRulePlugin.js +4 -6
- package/lib/runtime/StartupChunkDependenciesPlugin.js +39 -42
- package/lib/schemes/DataUriPlugin.js +5 -3
- package/lib/schemes/FileUriPlugin.js +5 -3
- package/lib/schemes/HttpUriPlugin.js +186 -188
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/ObjectMiddleware.js +13 -0
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +89 -33
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +306 -341
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +3 -3
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +35 -30
- package/schemas/WebpackOptions.check.d.ts +1 -1
- package/schemas/WebpackOptions.check.js +2 -2
- package/schemas/WebpackOptions.json +267 -26
- package/schemas/plugins/BannerPlugin.check.d.ts +1 -1
- package/schemas/plugins/BannerPlugin.check.js +1 -1
- package/schemas/plugins/DllPlugin.check.d.ts +1 -1
- package/schemas/plugins/DllPlugin.check.js +1 -1
- package/schemas/plugins/DllReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/DllReferencePlugin.check.js +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/HashedModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/IgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/IgnorePlugin.check.js +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.d.ts +1 -1
- package/schemas/plugins/LoaderOptionsPlugin.check.js +1 -1
- package/schemas/plugins/ProgressPlugin.check.d.ts +1 -1
- package/schemas/plugins/ProgressPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.d.ts +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.check.js +1 -1
- package/schemas/plugins/SourceMapDevToolPlugin.json +2 -2
- package/schemas/plugins/WatchIgnorePlugin.check.d.ts +1 -1
- package/schemas/plugins/WatchIgnorePlugin.check.js +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetInlineGeneratorOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetParserOptions.check.js +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/asset/AssetResourceGeneratorOptions.check.js +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerPlugin.check.js +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ContainerReferencePlugin.check.js +1 -1
- package/schemas/plugins/container/ExternalsType.check.d.ts +1 -1
- package/schemas/plugins/container/ExternalsType.check.js +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.d.ts +1 -1
- package/schemas/plugins/container/ModuleFederationPlugin.check.js +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssAutoParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssGlobalParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleGeneratorOptions.check.js +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssModuleParserOptions.check.js +1 -1
- package/schemas/plugins/css/CssParserOptions.check.d.ts +1 -1
- package/schemas/plugins/css/CssParserOptions.check.js +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.d.ts +1 -1
- package/schemas/plugins/debug/ProfilingPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceChunkIdsPlugin.check.js +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.d.ts +1 -1
- package/schemas/plugins/ids/OccurrenceModuleIdsPlugin.check.js +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginGenerator.check.js → json/JsonModulesPluginGenerator.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginGenerator.json +3 -0
- package/schemas/plugins/json/JsonModulesPluginParser.check.d.ts +7 -0
- package/schemas/plugins/{JsonModulesPluginParser.check.js → json/JsonModulesPluginParser.check.js} +1 -1
- package/schemas/plugins/json/JsonModulesPluginParser.json +3 -0
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.check.js +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/LimitChunkCountPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.d.ts +1 -1
- package/schemas/plugins/optimize/MinChunkSizePlugin.check.js +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.d.ts +1 -1
- package/schemas/plugins/schemes/HttpUriPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ConsumeSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/ProvideSharedPlugin.check.js +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.d.ts +1 -1
- package/schemas/plugins/sharing/SharePlugin.check.js +1 -1
- package/types.d.ts +587 -207
- package/schemas/plugins/JsonModulesPluginGenerator.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginGenerator.json +0 -11
- package/schemas/plugins/JsonModulesPluginParser.check.d.ts +0 -7
- package/schemas/plugins/JsonModulesPluginParser.json +0 -16
@@ -52,6 +52,8 @@ const isNotAEntryModule = (chunkGraph, chunk) => module =>
|
|
52
52
|
/** @type {WeakSet<Chunk>} */
|
53
53
|
const recordedChunks = new WeakSet();
|
54
54
|
|
55
|
+
const PLUGIN_NAME = "AggressiveSplittingPlugin";
|
56
|
+
|
55
57
|
class AggressiveSplittingPlugin {
|
56
58
|
/**
|
57
59
|
* @param {AggressiveSplittingPluginOptions=} options options object
|
@@ -88,261 +90,251 @@ class AggressiveSplittingPlugin {
|
|
88
90
|
* @returns {void}
|
89
91
|
*/
|
90
92
|
apply(compiler) {
|
91
|
-
compiler.hooks.thisCompilation.tap(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
93
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
94
|
+
let needAdditionalSeal = false;
|
95
|
+
/** @typedef {{ id?: NonNullable<Chunk["id"]>, hash?: NonNullable<Chunk["hash"]>, modules: Module[], size: number }} SplitData */
|
96
|
+
/** @type {SplitData[]} */
|
97
|
+
let newSplits;
|
98
|
+
/** @type {Set<Chunk>} */
|
99
|
+
let fromAggressiveSplittingSet;
|
100
|
+
/** @type {Map<Chunk, SplitData>} */
|
101
|
+
let chunkSplitDataMap;
|
102
|
+
compilation.hooks.optimize.tap(PLUGIN_NAME, () => {
|
103
|
+
newSplits = [];
|
104
|
+
fromAggressiveSplittingSet = new Set();
|
105
|
+
chunkSplitDataMap = new Map();
|
106
|
+
});
|
107
|
+
compilation.hooks.optimizeChunks.tap(
|
108
|
+
{
|
109
|
+
name: PLUGIN_NAME,
|
110
|
+
stage: STAGE_ADVANCED
|
111
|
+
},
|
112
|
+
chunks => {
|
113
|
+
const chunkGraph = compilation.chunkGraph;
|
114
|
+
// Precompute stuff
|
115
|
+
const nameToModuleMap = new Map();
|
116
|
+
const moduleToNameMap = new Map();
|
117
|
+
const makePathsRelative =
|
118
|
+
identifierUtils.makePathsRelative.bindContextCache(
|
119
|
+
compiler.context,
|
120
|
+
compiler.root
|
121
|
+
);
|
122
|
+
for (const m of compilation.modules) {
|
123
|
+
const name = makePathsRelative(m.identifier());
|
124
|
+
nameToModuleMap.set(name, m);
|
125
|
+
moduleToNameMap.set(m, name);
|
126
|
+
}
|
127
|
+
|
128
|
+
// Check used chunk ids
|
129
|
+
const usedIds = new Set();
|
130
|
+
for (const chunk of chunks) {
|
131
|
+
usedIds.add(chunk.id);
|
132
|
+
}
|
133
|
+
|
134
|
+
const recordedSplits =
|
135
|
+
(compilation.records && compilation.records.aggressiveSplits) || [];
|
136
|
+
const usedSplits = newSplits
|
137
|
+
? recordedSplits.concat(newSplits)
|
138
|
+
: recordedSplits;
|
127
139
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
140
|
+
const minSize = /** @type {number} */ (this.options.minSize);
|
141
|
+
const maxSize = /** @type {number} */ (this.options.maxSize);
|
142
|
+
|
143
|
+
/**
|
144
|
+
* @param {SplitData} splitData split data
|
145
|
+
* @returns {boolean} true when applied, otherwise false
|
146
|
+
*/
|
147
|
+
const applySplit = splitData => {
|
148
|
+
// Cannot split if id is already taken
|
149
|
+
if (splitData.id !== undefined && usedIds.has(splitData.id)) {
|
150
|
+
return false;
|
132
151
|
}
|
133
152
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
? recordedSplits.concat(newSplits)
|
139
|
-
: recordedSplits;
|
140
|
-
|
141
|
-
const minSize = /** @type {number} */ (this.options.minSize);
|
142
|
-
const maxSize = /** @type {number} */ (this.options.maxSize);
|
143
|
-
|
144
|
-
/**
|
145
|
-
* @param {SplitData} splitData split data
|
146
|
-
* @returns {boolean} true when applied, otherwise false
|
147
|
-
*/
|
148
|
-
const applySplit = splitData => {
|
149
|
-
// Cannot split if id is already taken
|
150
|
-
if (splitData.id !== undefined && usedIds.has(splitData.id)) {
|
151
|
-
return false;
|
152
|
-
}
|
153
|
+
// Get module objects from names
|
154
|
+
const selectedModules = splitData.modules.map(name =>
|
155
|
+
nameToModuleMap.get(name)
|
156
|
+
);
|
153
157
|
|
154
|
-
|
155
|
-
|
156
|
-
nameToModuleMap.get(name)
|
157
|
-
);
|
158
|
-
|
159
|
-
// Does the modules exist at all?
|
160
|
-
if (!selectedModules.every(Boolean)) return false;
|
161
|
-
|
162
|
-
// Check if size matches (faster than waiting for hash)
|
163
|
-
let size = 0;
|
164
|
-
for (const m of selectedModules) size += m.size();
|
165
|
-
if (size !== splitData.size) return false;
|
166
|
-
|
167
|
-
// get chunks with all modules
|
168
|
-
const selectedChunks = intersect(
|
169
|
-
selectedModules.map(
|
170
|
-
m => new Set(chunkGraph.getModuleChunksIterable(m))
|
171
|
-
)
|
172
|
-
);
|
173
|
-
|
174
|
-
// No relevant chunks found
|
175
|
-
if (selectedChunks.size === 0) return false;
|
176
|
-
|
177
|
-
// The found chunk is already the split or similar
|
178
|
-
if (
|
179
|
-
selectedChunks.size === 1 &&
|
180
|
-
chunkGraph.getNumberOfChunkModules(
|
181
|
-
Array.from(selectedChunks)[0]
|
182
|
-
) === selectedModules.length
|
183
|
-
) {
|
184
|
-
const chunk = Array.from(selectedChunks)[0];
|
185
|
-
if (fromAggressiveSplittingSet.has(chunk)) return false;
|
186
|
-
fromAggressiveSplittingSet.add(chunk);
|
187
|
-
chunkSplitDataMap.set(chunk, splitData);
|
188
|
-
return true;
|
189
|
-
}
|
158
|
+
// Does the modules exist at all?
|
159
|
+
if (!selectedModules.every(Boolean)) return false;
|
190
160
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
for (const module of selectedModules) {
|
196
|
-
moveModuleBetween(chunkGraph, chunk, newChunk)(module);
|
197
|
-
}
|
198
|
-
chunk.split(newChunk);
|
199
|
-
chunk.name = /** @type {TODO} */ (null);
|
200
|
-
}
|
201
|
-
fromAggressiveSplittingSet.add(newChunk);
|
202
|
-
chunkSplitDataMap.set(newChunk, splitData);
|
161
|
+
// Check if size matches (faster than waiting for hash)
|
162
|
+
let size = 0;
|
163
|
+
for (const m of selectedModules) size += m.size();
|
164
|
+
if (size !== splitData.size) return false;
|
203
165
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
166
|
+
// get chunks with all modules
|
167
|
+
const selectedChunks = intersect(
|
168
|
+
selectedModules.map(
|
169
|
+
m => new Set(chunkGraph.getModuleChunksIterable(m))
|
170
|
+
)
|
171
|
+
);
|
172
|
+
|
173
|
+
// No relevant chunks found
|
174
|
+
if (selectedChunks.size === 0) return false;
|
210
175
|
|
211
|
-
//
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
176
|
+
// The found chunk is already the split or similar
|
177
|
+
if (
|
178
|
+
selectedChunks.size === 1 &&
|
179
|
+
chunkGraph.getNumberOfChunkModules(
|
180
|
+
Array.from(selectedChunks)[0]
|
181
|
+
) === selectedModules.length
|
182
|
+
) {
|
183
|
+
const chunk = Array.from(selectedChunks)[0];
|
184
|
+
if (fromAggressiveSplittingSet.has(chunk)) return false;
|
185
|
+
fromAggressiveSplittingSet.add(chunk);
|
186
|
+
chunkSplitDataMap.set(chunk, splitData);
|
187
|
+
return true;
|
216
188
|
}
|
217
189
|
|
218
|
-
//
|
219
|
-
|
220
|
-
|
221
|
-
const
|
222
|
-
const
|
223
|
-
chunkGraph
|
224
|
-
chunkGraph.getChunkModulesSize(a);
|
225
|
-
if (diff1) return diff1;
|
226
|
-
const diff2 =
|
227
|
-
chunkGraph.getNumberOfChunkModules(a) -
|
228
|
-
chunkGraph.getNumberOfChunkModules(b);
|
229
|
-
if (diff2) return diff2;
|
230
|
-
return cmpFn(a, b);
|
231
|
-
});
|
232
|
-
for (const chunk of sortedChunks) {
|
233
|
-
if (fromAggressiveSplittingSet.has(chunk)) continue;
|
234
|
-
const size = chunkGraph.getChunkModulesSize(chunk);
|
235
|
-
if (
|
236
|
-
size > maxSize &&
|
237
|
-
chunkGraph.getNumberOfChunkModules(chunk) > 1
|
238
|
-
) {
|
239
|
-
const modules = chunkGraph
|
240
|
-
.getOrderedChunkModules(chunk, compareModulesByIdentifier)
|
241
|
-
.filter(isNotAEntryModule(chunkGraph, chunk));
|
242
|
-
const selectedModules = [];
|
243
|
-
let selectedModulesSize = 0;
|
244
|
-
for (let k = 0; k < modules.length; k++) {
|
245
|
-
const module = modules[k];
|
246
|
-
const newSize = selectedModulesSize + module.size();
|
247
|
-
if (newSize > maxSize && selectedModulesSize >= minSize) {
|
248
|
-
break;
|
249
|
-
}
|
250
|
-
selectedModulesSize = newSize;
|
251
|
-
selectedModules.push(module);
|
252
|
-
}
|
253
|
-
if (selectedModules.length === 0) continue;
|
254
|
-
/** @type {SplitData} */
|
255
|
-
const splitData = {
|
256
|
-
modules: selectedModules
|
257
|
-
.map(m => moduleToNameMap.get(m))
|
258
|
-
.sort(),
|
259
|
-
size: selectedModulesSize
|
260
|
-
};
|
261
|
-
|
262
|
-
if (applySplit(splitData)) {
|
263
|
-
newSplits = (newSplits || []).concat(splitData);
|
264
|
-
changed = true;
|
265
|
-
}
|
190
|
+
// split the chunk into two parts
|
191
|
+
const newChunk = compilation.addChunk();
|
192
|
+
newChunk.chunkReason = "aggressive splitted";
|
193
|
+
for (const chunk of selectedChunks) {
|
194
|
+
for (const module of selectedModules) {
|
195
|
+
moveModuleBetween(chunkGraph, chunk, newChunk)(module);
|
266
196
|
}
|
197
|
+
chunk.split(newChunk);
|
198
|
+
chunk.name = null;
|
267
199
|
}
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
// 4. save made splittings to records
|
275
|
-
const allSplits = new Set();
|
276
|
-
/** @type {Set<SplitData>} */
|
277
|
-
const invalidSplits = new Set();
|
278
|
-
|
279
|
-
// Check if some splittings are invalid
|
280
|
-
// We remove invalid splittings and try again
|
281
|
-
for (const chunk of compilation.chunks) {
|
282
|
-
const splitData = chunkSplitDataMap.get(chunk);
|
283
|
-
if (
|
284
|
-
splitData !== undefined &&
|
285
|
-
splitData.hash &&
|
286
|
-
chunk.hash !== splitData.hash
|
287
|
-
) {
|
288
|
-
// Split was successful, but hash doesn't equal
|
289
|
-
// We can throw away the split since it's useless now
|
290
|
-
invalidSplits.add(splitData);
|
291
|
-
}
|
200
|
+
fromAggressiveSplittingSet.add(newChunk);
|
201
|
+
chunkSplitDataMap.set(newChunk, splitData);
|
202
|
+
|
203
|
+
if (splitData.id !== null && splitData.id !== undefined) {
|
204
|
+
newChunk.id = splitData.id;
|
205
|
+
newChunk.ids = [splitData.id];
|
292
206
|
}
|
207
|
+
return true;
|
208
|
+
};
|
209
|
+
|
210
|
+
// try to restore to recorded splitting
|
211
|
+
let changed = false;
|
212
|
+
for (let j = 0; j < usedSplits.length; j++) {
|
213
|
+
const splitData = usedSplits[j];
|
214
|
+
if (applySplit(splitData)) changed = true;
|
215
|
+
}
|
293
216
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
217
|
+
// for any chunk which isn't splitted yet, split it and create a new entry
|
218
|
+
// start with the biggest chunk
|
219
|
+
const cmpFn = compareChunks(chunkGraph);
|
220
|
+
const sortedChunks = Array.from(chunks).sort((a, b) => {
|
221
|
+
const diff1 =
|
222
|
+
chunkGraph.getChunkModulesSize(b) -
|
223
|
+
chunkGraph.getChunkModulesSize(a);
|
224
|
+
if (diff1) return diff1;
|
225
|
+
const diff2 =
|
226
|
+
chunkGraph.getNumberOfChunkModules(a) -
|
227
|
+
chunkGraph.getNumberOfChunkModules(b);
|
228
|
+
if (diff2) return diff2;
|
229
|
+
return cmpFn(a, b);
|
230
|
+
});
|
231
|
+
for (const chunk of sortedChunks) {
|
232
|
+
if (fromAggressiveSplittingSet.has(chunk)) continue;
|
233
|
+
const size = chunkGraph.getChunkModulesSize(chunk);
|
234
|
+
if (
|
235
|
+
size > maxSize &&
|
236
|
+
chunkGraph.getNumberOfChunkModules(chunk) > 1
|
237
|
+
) {
|
238
|
+
const modules = chunkGraph
|
239
|
+
.getOrderedChunkModules(chunk, compareModulesByIdentifier)
|
240
|
+
.filter(isNotAEntryModule(chunkGraph, chunk));
|
241
|
+
const selectedModules = [];
|
242
|
+
let selectedModulesSize = 0;
|
243
|
+
for (let k = 0; k < modules.length; k++) {
|
244
|
+
const module = modules[k];
|
245
|
+
const newSize = selectedModulesSize + module.size();
|
246
|
+
if (newSize > maxSize && selectedModulesSize >= minSize) {
|
247
|
+
break;
|
315
248
|
}
|
249
|
+
selectedModulesSize = newSize;
|
250
|
+
selectedModules.push(module);
|
316
251
|
}
|
252
|
+
if (selectedModules.length === 0) continue;
|
253
|
+
/** @type {SplitData} */
|
254
|
+
const splitData = {
|
255
|
+
modules: selectedModules
|
256
|
+
.map(m => moduleToNameMap.get(m))
|
257
|
+
.sort(),
|
258
|
+
size: selectedModulesSize
|
259
|
+
};
|
317
260
|
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
compilation.records && compilation.records.aggressiveSplits;
|
322
|
-
if (recordedSplits) {
|
323
|
-
for (const splitData of recordedSplits) {
|
324
|
-
if (!invalidSplits.has(splitData)) allSplits.add(splitData);
|
325
|
-
}
|
261
|
+
if (applySplit(splitData)) {
|
262
|
+
newSplits = (newSplits || []).concat(splitData);
|
263
|
+
changed = true;
|
326
264
|
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
if (changed) return true;
|
268
|
+
}
|
269
|
+
);
|
270
|
+
compilation.hooks.recordHash.tap(PLUGIN_NAME, records => {
|
271
|
+
// 4. save made splittings to records
|
272
|
+
const allSplits = new Set();
|
273
|
+
/** @type {Set<SplitData>} */
|
274
|
+
const invalidSplits = new Set();
|
327
275
|
|
328
|
-
|
329
|
-
|
276
|
+
// Check if some splittings are invalid
|
277
|
+
// We remove invalid splittings and try again
|
278
|
+
for (const chunk of compilation.chunks) {
|
279
|
+
const splitData = chunkSplitDataMap.get(chunk);
|
280
|
+
if (
|
281
|
+
splitData !== undefined &&
|
282
|
+
splitData.hash &&
|
283
|
+
chunk.hash !== splitData.hash
|
284
|
+
) {
|
285
|
+
// Split was successful, but hash doesn't equal
|
286
|
+
// We can throw away the split since it's useless now
|
287
|
+
invalidSplits.add(splitData);
|
288
|
+
}
|
289
|
+
}
|
330
290
|
|
331
|
-
|
291
|
+
if (invalidSplits.size > 0) {
|
292
|
+
records.aggressiveSplits =
|
293
|
+
/** @type {SplitData[]} */
|
294
|
+
(records.aggressiveSplits).filter(
|
295
|
+
splitData => !invalidSplits.has(splitData)
|
296
|
+
);
|
297
|
+
needAdditionalSeal = true;
|
298
|
+
} else {
|
299
|
+
// set hash and id values on all (new) splittings
|
300
|
+
for (const chunk of compilation.chunks) {
|
301
|
+
const splitData = chunkSplitDataMap.get(chunk);
|
302
|
+
if (splitData !== undefined) {
|
303
|
+
splitData.hash =
|
304
|
+
/** @type {NonNullable<Chunk["hash"]>} */
|
305
|
+
(chunk.hash);
|
306
|
+
splitData.id =
|
307
|
+
/** @type {NonNullable<Chunk["id"]>} */
|
308
|
+
(chunk.id);
|
309
|
+
allSplits.add(splitData);
|
310
|
+
// set flag for stats
|
311
|
+
recordedChunks.add(chunk);
|
332
312
|
}
|
333
313
|
}
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
314
|
+
|
315
|
+
// Also add all unused historical splits (after the used ones)
|
316
|
+
// They can still be used in some future compilation
|
317
|
+
const recordedSplits =
|
318
|
+
compilation.records && compilation.records.aggressiveSplits;
|
319
|
+
if (recordedSplits) {
|
320
|
+
for (const splitData of recordedSplits) {
|
321
|
+
if (!invalidSplits.has(splitData)) allSplits.add(splitData);
|
341
322
|
}
|
342
323
|
}
|
343
|
-
|
344
|
-
|
345
|
-
|
324
|
+
|
325
|
+
// record all splits
|
326
|
+
records.aggressiveSplits = Array.from(allSplits);
|
327
|
+
|
328
|
+
needAdditionalSeal = false;
|
329
|
+
}
|
330
|
+
});
|
331
|
+
compilation.hooks.needAdditionalSeal.tap(PLUGIN_NAME, () => {
|
332
|
+
if (needAdditionalSeal) {
|
333
|
+
needAdditionalSeal = false;
|
334
|
+
return true;
|
335
|
+
}
|
336
|
+
});
|
337
|
+
});
|
346
338
|
}
|
347
339
|
}
|
348
340
|
module.exports = AggressiveSplittingPlugin;
|
@@ -84,6 +84,7 @@ const {
|
|
84
84
|
/** @typedef {import("../serialization/ObjectMiddleware").ObjectDeserializerContext} ObjectDeserializerContext */
|
85
85
|
/** @typedef {import("../util/Hash")} Hash */
|
86
86
|
/** @typedef {typeof import("../util/Hash")} HashConstructor */
|
87
|
+
/** @typedef {import("../util/concatenate").ScopeInfo} ScopeInfo */
|
87
88
|
/** @typedef {import("../util/concatenate").UsedNames} UsedNames */
|
88
89
|
/** @typedef {import("../util/fs").InputFileSystem} InputFileSystem */
|
89
90
|
/** @typedef {import("../util/identifier").AssociatedObjectForCache} AssociatedObjectForCache */
|
@@ -1138,13 +1139,8 @@ class ConcatenatedModule extends Module {
|
|
1138
1139
|
const topLevelDeclarations = new Set();
|
1139
1140
|
|
1140
1141
|
// List of additional names in scope for module references
|
1141
|
-
/** @type {Map<string,
|
1142
|
+
/** @type {Map<string, ScopeInfo>} */
|
1142
1143
|
const usedNamesInScopeInfo = new Map();
|
1143
|
-
/**
|
1144
|
-
* @param {string} module module identifier
|
1145
|
-
* @param {string} id export id
|
1146
|
-
* @returns {{ usedNames: UsedNames, alreadyCheckedScopes: Set<TODO> }} info
|
1147
|
-
*/
|
1148
1144
|
|
1149
1145
|
// Set of already checked scopes
|
1150
1146
|
const ignoredScopes = new Set();
|
@@ -1163,7 +1159,7 @@ class ConcatenatedModule extends Module {
|
|
1163
1159
|
const superClassCache = new WeakMap();
|
1164
1160
|
/**
|
1165
1161
|
* @param {Scope} scope scope
|
1166
|
-
* @returns {
|
1162
|
+
* @returns {{ range: Range, variables: Variable[] }[]} result
|
1167
1163
|
*/
|
1168
1164
|
const getSuperClassExpressions = scope => {
|
1169
1165
|
const cacheEntry = superClassCache.get(scope);
|
@@ -1178,7 +1174,7 @@ class ConcatenatedModule extends Module {
|
|
1178
1174
|
block.superClass
|
1179
1175
|
) {
|
1180
1176
|
superClassExpressions.push({
|
1181
|
-
range: block.superClass.range,
|
1177
|
+
range: /** @type {Range} */ (block.superClass.range),
|
1182
1178
|
variables: childScope.variables
|
1183
1179
|
});
|
1184
1180
|
}
|
@@ -1428,9 +1424,9 @@ class ConcatenatedModule extends Module {
|
|
1428
1424
|
/** @type {Set<string>} */
|
1429
1425
|
const unusedExports = new Set();
|
1430
1426
|
|
1431
|
-
const rootInfo =
|
1432
|
-
|
1433
|
-
|
1427
|
+
const rootInfo =
|
1428
|
+
/** @type {ConcatenatedModuleInfo} */
|
1429
|
+
(moduleToInfoMap.get(this.rootModule));
|
1434
1430
|
const strictHarmonyModule =
|
1435
1431
|
/** @type {BuildMeta} */
|
1436
1432
|
(rootInfo.module.buildMeta).strictHarmonyModule;
|
@@ -1632,7 +1628,8 @@ ${defineGetters}`
|
|
1632
1628
|
);
|
1633
1629
|
runtimeRequirements.add(RuntimeGlobals.require);
|
1634
1630
|
const { runtimeCondition } =
|
1635
|
-
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
1631
|
+
/** @type {ExternalModuleInfo | ReferenceToModuleInfo} */
|
1632
|
+
(rawInfo);
|
1636
1633
|
const condition = runtimeTemplate.runtimeConditionExpression({
|
1637
1634
|
chunkGraph,
|
1638
1635
|
runtimeCondition,
|
@@ -1730,9 +1727,9 @@ ${defineGetters}`
|
|
1730
1727
|
codeGenerationResults,
|
1731
1728
|
sourceTypes: JS_TYPES
|
1732
1729
|
});
|
1733
|
-
const source =
|
1734
|
-
|
1735
|
-
|
1730
|
+
const source =
|
1731
|
+
/** @type {Source} */
|
1732
|
+
(codeGenResult.sources.get("javascript"));
|
1736
1733
|
const data = codeGenResult.data;
|
1737
1734
|
const chunkInitFragments = data && data.get("chunkInitFragments");
|
1738
1735
|
const code = source.source().toString();
|
@@ -1742,7 +1739,9 @@ ${defineGetters}`
|
|
1742
1739
|
sourceType: "module"
|
1743
1740
|
});
|
1744
1741
|
} catch (_err) {
|
1745
|
-
const err =
|
1742
|
+
const err =
|
1743
|
+
/** @type {Error & { loc?: { line: number, column: number } }} */
|
1744
|
+
(_err);
|
1746
1745
|
if (
|
1747
1746
|
err.loc &&
|
1748
1747
|
typeof err.loc === "object" &&
|