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
|
@@ -16,7 +16,7 @@ const JsonParser = require("./JsonParser");
|
|
|
16
16
|
/** @typedef {import("../util/fs").JsonValue} JsonValue */
|
|
17
17
|
|
|
18
18
|
const validate = createSchemaValidation(
|
|
19
|
-
require("../../schemas/plugins/json/JsonModulesPluginParser.check
|
|
19
|
+
require("../../schemas/plugins/json/JsonModulesPluginParser.check"),
|
|
20
20
|
() => require("../../schemas/plugins/json/JsonModulesPluginParser.json"),
|
|
21
21
|
{
|
|
22
22
|
name: "Json Modules Plugin",
|
|
@@ -25,7 +25,7 @@ const validate = createSchemaValidation(
|
|
|
25
25
|
);
|
|
26
26
|
|
|
27
27
|
const validateGenerator = createSchemaValidation(
|
|
28
|
-
require("../../schemas/plugins/json/JsonModulesPluginGenerator.check
|
|
28
|
+
require("../../schemas/plugins/json/JsonModulesPluginGenerator.check"),
|
|
29
29
|
() => require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"),
|
|
30
30
|
{
|
|
31
31
|
name: "Json Modules Plugin",
|
package/lib/json/JsonParser.js
CHANGED
|
@@ -96,8 +96,9 @@ class AbstractLibraryPlugin {
|
|
|
96
96
|
* @returns {T | false} options for the chunk
|
|
97
97
|
*/
|
|
98
98
|
const getOptionsForChunk = chunk => {
|
|
99
|
-
if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0)
|
|
99
|
+
if (compilation.chunkGraph.getNumberOfEntryModules(chunk) === 0) {
|
|
100
100
|
return false;
|
|
101
|
+
}
|
|
101
102
|
const options = chunk.getEntryOptions();
|
|
102
103
|
const library = options && options.library;
|
|
103
104
|
return this._parseOptionsCached(
|
|
@@ -223,6 +224,7 @@ class AbstractLibraryPlugin {
|
|
|
223
224
|
*/
|
|
224
225
|
parseOptions(library) {
|
|
225
226
|
const AbstractMethodError = require("../AbstractMethodError");
|
|
227
|
+
|
|
226
228
|
throw new AbstractMethodError();
|
|
227
229
|
}
|
|
228
230
|
|
|
@@ -260,8 +262,9 @@ class AbstractLibraryPlugin {
|
|
|
260
262
|
* @returns {void}
|
|
261
263
|
*/
|
|
262
264
|
runtimeRequirements(chunk, set, libraryContext) {
|
|
263
|
-
if (this.render !== AbstractLibraryPlugin.prototype.render)
|
|
265
|
+
if (this.render !== AbstractLibraryPlugin.prototype.render) {
|
|
264
266
|
set.add(RuntimeGlobals.returnExportsFromRuntime);
|
|
267
|
+
}
|
|
265
268
|
}
|
|
266
269
|
|
|
267
270
|
/**
|
|
@@ -302,4 +305,5 @@ class AbstractLibraryPlugin {
|
|
|
302
305
|
}
|
|
303
306
|
|
|
304
307
|
AbstractLibraryPlugin.COMMON_LIBRARY_NAME_MESSAGE = COMMON_LIBRARY_NAME_MESSAGE;
|
|
308
|
+
|
|
305
309
|
module.exports = AbstractLibraryPlugin;
|
|
@@ -82,8 +82,9 @@ const accessWithInit = (accessor, existingLength, initLast = false) => {
|
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// print the last property as property access if not yet printed
|
|
85
|
-
if (i < accessor.length)
|
|
85
|
+
if (i < accessor.length) {
|
|
86
86
|
current = `${current}${propertyAccess([accessor[accessor.length - 1]])}`;
|
|
87
|
+
}
|
|
87
88
|
|
|
88
89
|
return current;
|
|
89
90
|
};
|
|
@@ -190,7 +191,12 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
190
191
|
*/
|
|
191
192
|
_getResolvedFullName(options, chunk, compilation) {
|
|
192
193
|
const prefix = this._getPrefix(compilation);
|
|
193
|
-
const fullName = options.name
|
|
194
|
+
const fullName = options.name
|
|
195
|
+
? [
|
|
196
|
+
...prefix,
|
|
197
|
+
...(Array.isArray(options.name) ? options.name : [options.name])
|
|
198
|
+
]
|
|
199
|
+
: prefix;
|
|
194
200
|
return fullName.map(n =>
|
|
195
201
|
compilation.getPath(n, {
|
|
196
202
|
chunk
|
|
@@ -241,16 +247,18 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
241
247
|
const topLevelDeclarations =
|
|
242
248
|
(data && data.get("topLevelDeclarations")) ||
|
|
243
249
|
(module.buildInfo && module.buildInfo.topLevelDeclarations);
|
|
244
|
-
if (!topLevelDeclarations)
|
|
250
|
+
if (!topLevelDeclarations) {
|
|
245
251
|
return "it doesn't tell about top level declarations.";
|
|
252
|
+
}
|
|
246
253
|
const fullNameResolved = this._getResolvedFullName(
|
|
247
254
|
options,
|
|
248
255
|
chunk,
|
|
249
256
|
compilation
|
|
250
257
|
);
|
|
251
258
|
const base = fullNameResolved[0];
|
|
252
|
-
if (topLevelDeclarations.has(base))
|
|
259
|
+
if (topLevelDeclarations.has(base)) {
|
|
253
260
|
return `it declares '${base}' on top-level, which conflicts with the current library output.`;
|
|
261
|
+
}
|
|
254
262
|
}
|
|
255
263
|
|
|
256
264
|
/**
|
|
@@ -325,6 +333,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
325
333
|
result.add(
|
|
326
334
|
`var __webpack_exports_export__ = ${RuntimeGlobals.exports}${exportAccess};\n`
|
|
327
335
|
);
|
|
336
|
+
|
|
328
337
|
exports = "__webpack_exports_export__";
|
|
329
338
|
}
|
|
330
339
|
result.add(`for(var __webpack_i__ in ${exports}) {\n`);
|
|
@@ -335,9 +344,14 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
335
344
|
);
|
|
336
345
|
}
|
|
337
346
|
result.add(
|
|
338
|
-
` ${
|
|
347
|
+
` ${
|
|
348
|
+
hasProvided ? " " : ""
|
|
349
|
+
}${webpackExportTarget}[__webpack_i__] = ${exports}[__webpack_i__];\n`
|
|
339
350
|
);
|
|
340
|
-
|
|
351
|
+
if (hasProvided) {
|
|
352
|
+
result.add(" }\n");
|
|
353
|
+
}
|
|
354
|
+
result.add("}\n");
|
|
341
355
|
result.add(
|
|
342
356
|
`Object.defineProperty(${exportTarget}, "__esModule", { value: true });\n`
|
|
343
357
|
);
|
|
@@ -355,6 +369,7 @@ class AssignLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
355
369
|
result.add(
|
|
356
370
|
`var __webpack_exports_export__ = ${RuntimeGlobals.exports}${exportAccess};\n`
|
|
357
371
|
);
|
|
372
|
+
|
|
358
373
|
exports = "__webpack_exports_export__";
|
|
359
374
|
}
|
|
360
375
|
result.add(
|
|
@@ -63,9 +63,7 @@ class EnableLibraryPlugin {
|
|
|
63
63
|
"EnableLibraryPlugin need to be used to enable this type of library. " +
|
|
64
64
|
'This usually happens through the "output.enabledLibraryTypes" option. ' +
|
|
65
65
|
'If you are using a function as entry which sets "library", you need to add all potential library types to "output.enabledLibraryTypes". ' +
|
|
66
|
-
`These types are enabled: ${
|
|
67
|
-
getEnabledTypes(compiler)
|
|
68
|
-
).join(", ")}`
|
|
66
|
+
`These types are enabled: ${[...getEnabledTypes(compiler)].join(", ")}`
|
|
69
67
|
);
|
|
70
68
|
}
|
|
71
69
|
}
|
|
@@ -90,6 +88,7 @@ class EnableLibraryPlugin {
|
|
|
90
88
|
if (typeof type === "string") {
|
|
91
89
|
const enableExportProperty = () => {
|
|
92
90
|
const ExportPropertyTemplatePlugin = require("./ExportPropertyLibraryPlugin");
|
|
91
|
+
|
|
93
92
|
new ExportPropertyTemplatePlugin({
|
|
94
93
|
type,
|
|
95
94
|
nsObjectUsed: !["module", "modern-module"].includes(type),
|
|
@@ -101,6 +100,7 @@ class EnableLibraryPlugin {
|
|
|
101
100
|
case "var": {
|
|
102
101
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
103
102
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
103
|
+
|
|
104
104
|
new AssignLibraryPlugin({
|
|
105
105
|
type,
|
|
106
106
|
prefix: [],
|
|
@@ -112,6 +112,7 @@ class EnableLibraryPlugin {
|
|
|
112
112
|
case "assign-properties": {
|
|
113
113
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
114
114
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
115
|
+
|
|
115
116
|
new AssignLibraryPlugin({
|
|
116
117
|
type,
|
|
117
118
|
prefix: [],
|
|
@@ -124,6 +125,7 @@ class EnableLibraryPlugin {
|
|
|
124
125
|
case "assign": {
|
|
125
126
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
126
127
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
128
|
+
|
|
127
129
|
new AssignLibraryPlugin({
|
|
128
130
|
type,
|
|
129
131
|
prefix: [],
|
|
@@ -135,6 +137,7 @@ class EnableLibraryPlugin {
|
|
|
135
137
|
case "this": {
|
|
136
138
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
137
139
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
140
|
+
|
|
138
141
|
new AssignLibraryPlugin({
|
|
139
142
|
type,
|
|
140
143
|
prefix: ["this"],
|
|
@@ -146,6 +149,7 @@ class EnableLibraryPlugin {
|
|
|
146
149
|
case "window": {
|
|
147
150
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
148
151
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
152
|
+
|
|
149
153
|
new AssignLibraryPlugin({
|
|
150
154
|
type,
|
|
151
155
|
prefix: ["window"],
|
|
@@ -157,6 +161,7 @@ class EnableLibraryPlugin {
|
|
|
157
161
|
case "self": {
|
|
158
162
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
159
163
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
164
|
+
|
|
160
165
|
new AssignLibraryPlugin({
|
|
161
166
|
type,
|
|
162
167
|
prefix: ["self"],
|
|
@@ -168,6 +173,7 @@ class EnableLibraryPlugin {
|
|
|
168
173
|
case "global": {
|
|
169
174
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
170
175
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
176
|
+
|
|
171
177
|
new AssignLibraryPlugin({
|
|
172
178
|
type,
|
|
173
179
|
prefix: "global",
|
|
@@ -179,6 +185,7 @@ class EnableLibraryPlugin {
|
|
|
179
185
|
case "commonjs": {
|
|
180
186
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
181
187
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
188
|
+
|
|
182
189
|
new AssignLibraryPlugin({
|
|
183
190
|
type,
|
|
184
191
|
prefix: ["exports"],
|
|
@@ -190,6 +197,7 @@ class EnableLibraryPlugin {
|
|
|
190
197
|
case "commonjs-static": {
|
|
191
198
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
192
199
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
200
|
+
|
|
193
201
|
new AssignLibraryPlugin({
|
|
194
202
|
type,
|
|
195
203
|
prefix: ["exports"],
|
|
@@ -202,6 +210,7 @@ class EnableLibraryPlugin {
|
|
|
202
210
|
case "commonjs-module": {
|
|
203
211
|
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/41697
|
|
204
212
|
const AssignLibraryPlugin = require("./AssignLibraryPlugin");
|
|
213
|
+
|
|
205
214
|
new AssignLibraryPlugin({
|
|
206
215
|
type,
|
|
207
216
|
prefix: ["module", "exports"],
|
|
@@ -213,7 +222,9 @@ class EnableLibraryPlugin {
|
|
|
213
222
|
case "amd":
|
|
214
223
|
case "amd-require": {
|
|
215
224
|
enableExportProperty();
|
|
225
|
+
|
|
216
226
|
const AmdLibraryPlugin = require("./AmdLibraryPlugin");
|
|
227
|
+
|
|
217
228
|
new AmdLibraryPlugin({
|
|
218
229
|
type,
|
|
219
230
|
requireAsWrapper: type === "amd-require"
|
|
@@ -234,6 +245,7 @@ class EnableLibraryPlugin {
|
|
|
234
245
|
"WarnFalseIifeUmdPlugin",
|
|
235
246
|
compilation => {
|
|
236
247
|
const FalseIIFEUmdWarning = require("../FalseIIFEUmdWarning");
|
|
248
|
+
|
|
237
249
|
compilation.warnings.push(new FalseIIFEUmdWarning());
|
|
238
250
|
}
|
|
239
251
|
);
|
|
@@ -243,7 +255,9 @@ class EnableLibraryPlugin {
|
|
|
243
255
|
new WarnFalseIifeUmdPlugin().apply(compiler);
|
|
244
256
|
}
|
|
245
257
|
enableExportProperty();
|
|
258
|
+
|
|
246
259
|
const UmdLibraryPlugin = require("./UmdLibraryPlugin");
|
|
260
|
+
|
|
247
261
|
new UmdLibraryPlugin({
|
|
248
262
|
type,
|
|
249
263
|
optionalAmdExternalAsGlobal: type === "umd2"
|
|
@@ -252,7 +266,9 @@ class EnableLibraryPlugin {
|
|
|
252
266
|
}
|
|
253
267
|
case "system": {
|
|
254
268
|
enableExportProperty();
|
|
269
|
+
|
|
255
270
|
const SystemLibraryPlugin = require("./SystemLibraryPlugin");
|
|
271
|
+
|
|
256
272
|
new SystemLibraryPlugin({
|
|
257
273
|
type
|
|
258
274
|
}).apply(compiler);
|
|
@@ -260,7 +276,9 @@ class EnableLibraryPlugin {
|
|
|
260
276
|
}
|
|
261
277
|
case "jsonp": {
|
|
262
278
|
enableExportProperty();
|
|
279
|
+
|
|
263
280
|
const JsonpLibraryPlugin = require("./JsonpLibraryPlugin");
|
|
281
|
+
|
|
264
282
|
new JsonpLibraryPlugin({
|
|
265
283
|
type
|
|
266
284
|
}).apply(compiler);
|
|
@@ -269,7 +287,9 @@ class EnableLibraryPlugin {
|
|
|
269
287
|
case "module":
|
|
270
288
|
case "modern-module": {
|
|
271
289
|
enableExportProperty();
|
|
290
|
+
|
|
272
291
|
const ModuleLibraryPlugin = require("./ModuleLibraryPlugin");
|
|
292
|
+
|
|
273
293
|
new ModuleLibraryPlugin({
|
|
274
294
|
type
|
|
275
295
|
}).apply(compiler);
|
|
@@ -47,8 +47,9 @@ const accessorAccess = (base, accessor, joinWith = ", ") => {
|
|
|
47
47
|
? base + accessorToObjectAccess(accessors.slice(0, idx + 1))
|
|
48
48
|
: accessors[0] + accessorToObjectAccess(accessors.slice(1, idx + 1));
|
|
49
49
|
if (idx === accessors.length - 1) return a;
|
|
50
|
-
if (idx === 0 && base === undefined)
|
|
50
|
+
if (idx === 0 && base === undefined) {
|
|
51
51
|
return `${a} = typeof ${a} === "object" ? ${a} : {}`;
|
|
52
|
+
}
|
|
52
53
|
return `${a} = ${a} || {}`;
|
|
53
54
|
})
|
|
54
55
|
.join(joinWith);
|
|
@@ -147,7 +148,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
147
148
|
requiredExternals.push(m);
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
|
-
externals = requiredExternals
|
|
151
|
+
externals = [...requiredExternals, ...optionalExternals];
|
|
151
152
|
} else {
|
|
152
153
|
requiredExternals = externals;
|
|
153
154
|
}
|
|
@@ -188,11 +189,15 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
188
189
|
modules
|
|
189
190
|
.map(m => {
|
|
190
191
|
let request = m.request;
|
|
191
|
-
if (typeof request === "object")
|
|
192
|
+
if (typeof request === "object") {
|
|
192
193
|
request =
|
|
193
194
|
/** @type {RequestRecord} */
|
|
194
195
|
(request).root;
|
|
195
|
-
|
|
196
|
+
}
|
|
197
|
+
return `root${accessorToObjectAccess(
|
|
198
|
+
/** @type {string[]} */
|
|
199
|
+
([...(Array.isArray(request) ? request : [request])])
|
|
200
|
+
)}`;
|
|
196
201
|
})
|
|
197
202
|
.join(", ")
|
|
198
203
|
);
|
|
@@ -252,7 +257,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
252
257
|
JSON.stringify(
|
|
253
258
|
replaceKeys(
|
|
254
259
|
/** @type {string} */
|
|
255
|
-
(
|
|
260
|
+
(
|
|
261
|
+
/** @type {string[]} */
|
|
262
|
+
([...(Array.isArray(library) ? library : [library])]).pop()
|
|
263
|
+
)
|
|
256
264
|
)
|
|
257
265
|
);
|
|
258
266
|
|
|
@@ -281,8 +289,9 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
281
289
|
*/
|
|
282
290
|
const getAuxiliaryComment = type => {
|
|
283
291
|
if (auxiliaryComment) {
|
|
284
|
-
if (typeof auxiliaryComment === "string")
|
|
292
|
+
if (typeof auxiliaryComment === "string") {
|
|
285
293
|
return `\t//${auxiliaryComment}\n`;
|
|
294
|
+
}
|
|
286
295
|
if (auxiliaryComment[type]) return `\t//${auxiliaryComment[type]}\n`;
|
|
287
296
|
}
|
|
288
297
|
return "";
|
|
@@ -85,9 +85,9 @@ module.exports = ({ level = "info", debug = false, console }) => {
|
|
|
85
85
|
(
|
|
86
86
|
typeof debug === "boolean"
|
|
87
87
|
? [() => debug]
|
|
88
|
-
: /** @type {FilterItemTypes[]} */ ([
|
|
89
|
-
.
|
|
90
|
-
|
|
88
|
+
: /** @type {FilterItemTypes[]} */ ([
|
|
89
|
+
...(Array.isArray(debug) ? debug : [debug])
|
|
90
|
+
]).map(filterToFunction)
|
|
91
91
|
);
|
|
92
92
|
const loglevel = LogLevel[`${level}`] || 0;
|
|
93
93
|
|
package/lib/logging/runtime.js
CHANGED
|
@@ -17,6 +17,15 @@ const currentDefaultLoggerOptions = {
|
|
|
17
17
|
};
|
|
18
18
|
let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
|
|
22
|
+
* @returns {void}
|
|
23
|
+
*/
|
|
24
|
+
module.exports.configureDefaultLogger = options => {
|
|
25
|
+
Object.assign(currentDefaultLoggerOptions, options);
|
|
26
|
+
currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|
27
|
+
};
|
|
28
|
+
|
|
20
29
|
/**
|
|
21
30
|
* @param {string} name name of the logger
|
|
22
31
|
* @returns {Logger} a logger
|
|
@@ -31,15 +40,6 @@ module.exports.getLogger = name =>
|
|
|
31
40
|
childName => module.exports.getLogger(`${name}/${childName}`)
|
|
32
41
|
);
|
|
33
42
|
|
|
34
|
-
/**
|
|
35
|
-
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
|
|
36
|
-
* @returns {void}
|
|
37
|
-
*/
|
|
38
|
-
module.exports.configureDefaultLogger = options => {
|
|
39
|
-
Object.assign(currentDefaultLoggerOptions, options);
|
|
40
|
-
currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
43
|
module.exports.hooks = {
|
|
44
44
|
log: new SyncBailHook(["origin", "type", "args"])
|
|
45
45
|
};
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
|
10
|
+
const {
|
|
11
|
+
generateJavascriptHMR
|
|
12
|
+
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
|
10
13
|
const {
|
|
11
14
|
chunkHasJs,
|
|
12
15
|
getChunkFilenameTemplate
|
|
@@ -242,28 +245,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
242
245
|
]),
|
|
243
246
|
"}",
|
|
244
247
|
"",
|
|
245
|
-
|
|
246
|
-
require("../hmr/JavascriptHotModuleReplacement.runtime.js")
|
|
247
|
-
)
|
|
248
|
-
.replace(/\$key\$/g, "readFileVm")
|
|
249
|
-
.replace(/\$installedChunks\$/g, "installedChunks")
|
|
250
|
-
.replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk")
|
|
251
|
-
.replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
|
|
252
|
-
.replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories)
|
|
253
|
-
.replace(
|
|
254
|
-
/\$ensureChunkHandlers\$/g,
|
|
255
|
-
RuntimeGlobals.ensureChunkHandlers
|
|
256
|
-
)
|
|
257
|
-
.replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty)
|
|
258
|
-
.replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData)
|
|
259
|
-
.replace(
|
|
260
|
-
/\$hmrDownloadUpdateHandlers\$/g,
|
|
261
|
-
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
262
|
-
)
|
|
263
|
-
.replace(
|
|
264
|
-
/\$hmrInvalidateModuleHandlers\$/g,
|
|
265
|
-
RuntimeGlobals.hmrInvalidateModuleHandlers
|
|
266
|
-
)
|
|
248
|
+
generateJavascriptHMR("readFileVm")
|
|
267
249
|
])
|
|
268
250
|
: "// no HMR",
|
|
269
251
|
"",
|
|
@@ -7,6 +7,9 @@
|
|
|
7
7
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
8
8
|
const RuntimeModule = require("../RuntimeModule");
|
|
9
9
|
const Template = require("../Template");
|
|
10
|
+
const {
|
|
11
|
+
generateJavascriptHMR
|
|
12
|
+
} = require("../hmr/JavascriptHotModuleReplacementHelper");
|
|
10
13
|
const {
|
|
11
14
|
chunkHasJs,
|
|
12
15
|
getChunkFilenameTemplate
|
|
@@ -199,28 +202,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
199
202
|
]),
|
|
200
203
|
"}",
|
|
201
204
|
"",
|
|
202
|
-
|
|
203
|
-
require("../hmr/JavascriptHotModuleReplacement.runtime.js")
|
|
204
|
-
)
|
|
205
|
-
.replace(/\$key\$/g, "require")
|
|
206
|
-
.replace(/\$installedChunks\$/g, "installedChunks")
|
|
207
|
-
.replace(/\$loadUpdateChunk\$/g, "loadUpdateChunk")
|
|
208
|
-
.replace(/\$moduleCache\$/g, RuntimeGlobals.moduleCache)
|
|
209
|
-
.replace(/\$moduleFactories\$/g, RuntimeGlobals.moduleFactories)
|
|
210
|
-
.replace(
|
|
211
|
-
/\$ensureChunkHandlers\$/g,
|
|
212
|
-
RuntimeGlobals.ensureChunkHandlers
|
|
213
|
-
)
|
|
214
|
-
.replace(/\$hasOwnProperty\$/g, RuntimeGlobals.hasOwnProperty)
|
|
215
|
-
.replace(/\$hmrModuleData\$/g, RuntimeGlobals.hmrModuleData)
|
|
216
|
-
.replace(
|
|
217
|
-
/\$hmrDownloadUpdateHandlers\$/g,
|
|
218
|
-
RuntimeGlobals.hmrDownloadUpdateHandlers
|
|
219
|
-
)
|
|
220
|
-
.replace(
|
|
221
|
-
/\$hmrInvalidateModuleHandlers\$/g,
|
|
222
|
-
RuntimeGlobals.hmrInvalidateModuleHandlers
|
|
223
|
-
)
|
|
205
|
+
generateJavascriptHMR("require")
|
|
224
206
|
])
|
|
225
207
|
: "// no HMR",
|
|
226
208
|
"",
|
package/lib/node/nodeConsole.js
CHANGED
|
@@ -124,9 +124,11 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
|
|
124
124
|
currentCollapsed++;
|
|
125
125
|
},
|
|
126
126
|
groupEnd: () => {
|
|
127
|
-
if (currentCollapsed > 0)
|
|
128
|
-
|
|
127
|
+
if (currentCollapsed > 0) {
|
|
128
|
+
currentCollapsed--;
|
|
129
|
+
} else if (currentIndent.length >= 2) {
|
|
129
130
|
currentIndent = currentIndent.slice(0, -2);
|
|
131
|
+
}
|
|
130
132
|
},
|
|
131
133
|
profile: console.profile && (name => console.profile(name)),
|
|
132
134
|
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
|
|
@@ -15,6 +15,8 @@ const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
|
15
15
|
* @property {number=} minSizeReduce minimal size reduction to trigger merging
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
+
const PLUGIN_NAME = "AggressiveMergingPlugin";
|
|
19
|
+
|
|
18
20
|
class AggressiveMergingPlugin {
|
|
19
21
|
/**
|
|
20
22
|
* @param {AggressiveMergingPluginOptions=} options options object
|
|
@@ -40,58 +42,55 @@ class AggressiveMergingPlugin {
|
|
|
40
42
|
const options = this.options;
|
|
41
43
|
const minSizeReduce = options.minSizeReduce || 1.5;
|
|
42
44
|
|
|
43
|
-
compiler.hooks.thisCompilation.tap(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
for (const
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (!chunkGraph.canChunksBeIntegrated(a, b)) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
const aSize = chunkGraph.getChunkSize(b, {
|
|
64
|
-
chunkOverhead: 0
|
|
65
|
-
});
|
|
66
|
-
const bSize = chunkGraph.getChunkSize(a, {
|
|
67
|
-
chunkOverhead: 0
|
|
68
|
-
});
|
|
69
|
-
const abSize = chunkGraph.getIntegratedChunksSize(b, a, {
|
|
70
|
-
chunkOverhead: 0
|
|
71
|
-
});
|
|
72
|
-
const improvement = (aSize + bSize) / abSize;
|
|
73
|
-
combinations.push({
|
|
74
|
-
a,
|
|
75
|
-
b,
|
|
76
|
-
improvement
|
|
77
|
-
});
|
|
45
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
46
|
+
compilation.hooks.optimizeChunks.tap(
|
|
47
|
+
{
|
|
48
|
+
name: PLUGIN_NAME,
|
|
49
|
+
stage: STAGE_ADVANCED
|
|
50
|
+
},
|
|
51
|
+
chunks => {
|
|
52
|
+
const chunkGraph = compilation.chunkGraph;
|
|
53
|
+
/** @type {{a: Chunk, b: Chunk, improvement: number}[]} */
|
|
54
|
+
const combinations = [];
|
|
55
|
+
for (const a of chunks) {
|
|
56
|
+
if (a.canBeInitial()) continue;
|
|
57
|
+
for (const b of chunks) {
|
|
58
|
+
if (b.canBeInitial()) continue;
|
|
59
|
+
if (b === a) break;
|
|
60
|
+
if (!chunkGraph.canChunksBeIntegrated(a, b)) {
|
|
61
|
+
continue;
|
|
78
62
|
}
|
|
63
|
+
const aSize = chunkGraph.getChunkSize(b, {
|
|
64
|
+
chunkOverhead: 0
|
|
65
|
+
});
|
|
66
|
+
const bSize = chunkGraph.getChunkSize(a, {
|
|
67
|
+
chunkOverhead: 0
|
|
68
|
+
});
|
|
69
|
+
const abSize = chunkGraph.getIntegratedChunksSize(b, a, {
|
|
70
|
+
chunkOverhead: 0
|
|
71
|
+
});
|
|
72
|
+
const improvement = (aSize + bSize) / abSize;
|
|
73
|
+
combinations.push({
|
|
74
|
+
a,
|
|
75
|
+
b,
|
|
76
|
+
improvement
|
|
77
|
+
});
|
|
79
78
|
}
|
|
79
|
+
}
|
|
80
80
|
|
|
81
|
-
|
|
81
|
+
combinations.sort((a, b) => b.improvement - a.improvement);
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
const pair = combinations[0];
|
|
84
84
|
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
if (!pair) return;
|
|
86
|
+
if (pair.improvement < minSizeReduce) return;
|
|
87
87
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
);
|
|
88
|
+
chunkGraph.integrateChunks(pair.b, pair.a);
|
|
89
|
+
compilation.chunks.delete(pair.a);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
);
|
|
93
|
+
});
|
|
95
94
|
}
|
|
96
95
|
}
|
|
97
96
|
|