webpack 5.99.5 → 5.99.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/APIPlugin.js +2 -2
- package/lib/AutomaticPrefetchPlugin.js +21 -22
- package/lib/BannerPlugin.js +31 -35
- package/lib/Cache.js +1 -1
- package/lib/Chunk.js +12 -9
- package/lib/CleanPlugin.js +5 -3
- package/lib/Compilation.js +45 -35
- package/lib/Compiler.js +6 -4
- package/lib/ContextExclusionPlugin.js +4 -2
- package/lib/ContextModule.js +2 -1
- package/lib/ContextReplacementPlugin.js +5 -3
- 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 +137 -138
- package/lib/ExternalsPlugin.js +3 -1
- package/lib/FlagDependencyExportsPlugin.js +2 -1
- package/lib/HotModuleReplacementPlugin.js +3 -3
- package/lib/IgnorePlugin.js +6 -4
- package/lib/IgnoreWarningsPlugin.js +4 -2
- package/lib/LibManifestPlugin.js +3 -4
- package/lib/LoaderOptionsPlugin.js +4 -2
- package/lib/LoaderTargetPlugin.js +4 -2
- package/lib/Module.js +29 -14
- package/lib/ModuleFilenameHelpers.js +1 -1
- package/lib/ModuleGraph.js +15 -10
- package/lib/ModuleInfoHeaderPlugin.js +11 -12
- package/lib/MultiCompiler.js +5 -3
- package/lib/NoEmitOnErrorsPlugin.js +5 -3
- package/lib/NormalModule.js +6 -2
- package/lib/NormalModuleReplacementPlugin.js +33 -36
- package/lib/PlatformPlugin.js +3 -1
- package/lib/PrefetchPlugin.js +5 -3
- package/lib/ProgressPlugin.js +23 -26
- package/lib/RecordIdsPlugin.js +73 -103
- package/lib/RuntimePlugin.js +34 -32
- package/lib/SourceMapDevToolPlugin.js +8 -6
- package/lib/Template.js +1 -1
- 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 +22 -5
- package/lib/async-modules/InferAsyncModulesPlugin.js +25 -26
- package/lib/buildChunkGraph.js +7 -2
- package/lib/cache/IdleFileCachePlugin.js +12 -13
- package/lib/cache/MemoryCachePlugin.js +2 -1
- package/lib/cache/MemoryWithGcCachePlugin.js +10 -7
- package/lib/cache/PackFileCacheStrategy.js +13 -21
- package/lib/cache/ResolverCachePlugin.js +22 -22
- package/lib/cli.js +8 -4
- package/lib/config/defaults.js +2 -2
- package/lib/config/normalization.js +9 -3
- package/lib/config/target.js +6 -6
- 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 +6 -4
- package/lib/css/CssParser.js +1 -1
- package/lib/debug/ProfilingPlugin.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +1 -1
- package/lib/dependencies/CssIcssImportDependency.js +3 -2
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +9 -15
- package/lib/dependencies/HarmonyExportExpressionDependency.js +1 -1
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +1 -1
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +15 -15
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -2
- package/lib/dependencies/JsonExportsDependency.js +1 -1
- package/lib/dependencies/LoaderPlugin.js +5 -3
- package/lib/dependencies/LocalModulesHelpers.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +46 -46
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +94 -100
- package/lib/dependencies/RequireResolveDependency.js +1 -1
- package/lib/dependencies/WorkerPlugin.js +2 -2
- package/lib/esm/ModuleChunkLoadingPlugin.js +76 -57
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +11 -9
- package/lib/hmr/HotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +0 -1
- package/lib/hmr/LazyCompilationPlugin.js +17 -18
- package/lib/ids/ChunkModuleIdRangePlugin.js +6 -6
- package/lib/ids/DeterministicChunkIdsPlugin.js +1 -1
- package/lib/ids/DeterministicModuleIdsPlugin.js +48 -49
- package/lib/ids/HashedModuleIdsPlugin.js +4 -2
- package/lib/ids/NamedChunkIdsPlugin.js +6 -4
- package/lib/ids/NamedModuleIdsPlugin.js +6 -4
- 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 +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +2 -2
- package/lib/javascript/JavascriptParser.js +670 -688
- package/lib/library/EnableLibraryPlugin.js +15 -2
- package/lib/library/ModuleLibraryPlugin.js +66 -43
- package/lib/logging/createConsoleLogger.js +0 -1
- package/lib/node/CommonJsChunkLoadingPlugin.js +71 -75
- package/lib/node/NodeEnvironmentPlugin.js +3 -1
- package/lib/node/NodeTemplatePlugin.js +2 -2
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +2 -2
- package/lib/node/ReadFileCompileWasmPlugin.js +3 -3
- package/lib/optimize/AggressiveMergingPlugin.js +1 -1
- package/lib/optimize/AggressiveSplittingPlugin.js +224 -232
- package/lib/optimize/ConcatenatedModule.js +12 -15
- 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 +4 -2
- 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 +17 -18
- package/lib/optimize/SplitChunksPlugin.js +9 -6
- package/lib/performance/SizeLimitsPlugin.js +3 -1
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +61 -62
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +3 -4
- 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 +32 -39
- package/lib/serialization/AggregateErrorSerializer.js +42 -0
- package/lib/serialization/BinaryMiddleware.js +22 -38
- package/lib/serialization/ErrorObjectSerializer.js +7 -2
- package/lib/serialization/FileMiddleware.js +29 -33
- package/lib/serialization/ObjectMiddleware.js +42 -30
- package/lib/serialization/Serializer.js +29 -18
- package/lib/serialization/SerializerMiddleware.js +105 -72
- package/lib/serialization/SingleItemMiddleware.js +4 -5
- package/lib/sharing/ProvideSharedPlugin.js +6 -4
- package/lib/stats/DefaultStatsFactoryPlugin.js +128 -57
- package/lib/stats/DefaultStatsPresetPlugin.js +25 -20
- package/lib/stats/DefaultStatsPrinterPlugin.js +486 -334
- package/lib/stats/StatsFactory.js +47 -10
- package/lib/stats/StatsPrinter.js +52 -31
- package/lib/util/ArrayQueue.js +1 -1
- package/lib/util/AsyncQueue.js +1 -1
- package/lib/util/TupleQueue.js +9 -7
- package/lib/util/TupleSet.js +37 -18
- package/lib/util/WeakTupleMap.js +50 -37
- package/lib/util/cleverMerge.js +2 -2
- package/lib/util/comparators.js +1 -1
- package/lib/util/concatenate.js +4 -2
- package/lib/util/createHash.js +1 -1
- package/lib/util/fs.js +1 -1
- package/lib/util/makeSerializable.js +1 -1
- package/lib/util/runtime.js +1 -0
- package/lib/util/serialization.js +50 -42
- package/lib/wasm-async/AsyncWebAssemblyGenerator.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +1 -1
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +2 -2
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +55 -57
- package/lib/wasm-sync/WebAssemblyGenerator.js +1 -1
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +1 -1
- package/lib/web/FetchCompileWasmPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingPlugin.js +73 -74
- package/lib/webpack.js +1 -1
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +77 -78
- package/package.json +4 -3
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +24 -2
- package/types.d.ts +273 -128
@@ -12,6 +12,8 @@ const { compareIds } = require("../util/comparators");
|
|
12
12
|
/** @typedef {import("../Compiler")} Compiler */
|
13
13
|
/** @typedef {import("../Module")} Module */
|
14
14
|
|
15
|
+
const PLUGIN_NAME = "FlagIncludedChunksPlugin";
|
16
|
+
|
15
17
|
class FlagIncludedChunksPlugin {
|
16
18
|
/**
|
17
19
|
* Apply the plugin
|
@@ -19,111 +21,104 @@ class FlagIncludedChunksPlugin {
|
|
19
21
|
* @returns {void}
|
20
22
|
*/
|
21
23
|
apply(compiler) {
|
22
|
-
compiler.hooks.compilation.tap(
|
23
|
-
compilation.hooks.optimizeChunkIds.tap(
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
let i = 0;
|
52
|
-
for (const module of compilation.modules) {
|
53
|
-
let bit = 30;
|
54
|
-
while (i % modulos[bit] !== 0) {
|
55
|
-
bit--;
|
56
|
-
}
|
57
|
-
moduleBits.set(module, 1 << bit);
|
58
|
-
i++;
|
24
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
25
|
+
compilation.hooks.optimizeChunkIds.tap(PLUGIN_NAME, chunks => {
|
26
|
+
const chunkGraph = compilation.chunkGraph;
|
27
|
+
|
28
|
+
// prepare two bit integers for each module
|
29
|
+
// 2^31 is the max number represented as SMI in v8
|
30
|
+
// we want the bits distributed this way:
|
31
|
+
// the bit 2^31 is pretty rar and only one module should get it
|
32
|
+
// so it has a probability of 1 / modulesCount
|
33
|
+
// the first bit (2^0) is the easiest and every module could get it
|
34
|
+
// if it doesn't get a better bit
|
35
|
+
// from bit 2^n to 2^(n+1) there is a probability of p
|
36
|
+
// so 1 / modulesCount == p^31
|
37
|
+
// <=> p = sqrt31(1 / modulesCount)
|
38
|
+
// so we use a modulo of 1 / sqrt31(1 / modulesCount)
|
39
|
+
/** @type {WeakMap<Module, number>} */
|
40
|
+
const moduleBits = new WeakMap();
|
41
|
+
const modulesCount = compilation.modules.size;
|
42
|
+
|
43
|
+
// precalculate the modulo values for each bit
|
44
|
+
const modulo = 1 / (1 / modulesCount) ** (1 / 31);
|
45
|
+
const modulos = Array.from({ length: 31 }, (x, i) => (modulo ** i) | 0);
|
46
|
+
|
47
|
+
// iterate all modules to generate bit values
|
48
|
+
let i = 0;
|
49
|
+
for (const module of compilation.modules) {
|
50
|
+
let bit = 30;
|
51
|
+
while (i % modulos[bit] !== 0) {
|
52
|
+
bit--;
|
59
53
|
}
|
54
|
+
moduleBits.set(module, 1 << bit);
|
55
|
+
i++;
|
56
|
+
}
|
60
57
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
58
|
+
// iterate all chunks to generate bitmaps
|
59
|
+
/** @type {WeakMap<Chunk, number>} */
|
60
|
+
const chunkModulesHash = new WeakMap();
|
61
|
+
for (const chunk of chunks) {
|
62
|
+
let hash = 0;
|
63
|
+
for (const module of chunkGraph.getChunkModulesIterable(chunk)) {
|
64
|
+
hash |= /** @type {number} */ (moduleBits.get(module));
|
65
|
+
}
|
66
|
+
chunkModulesHash.set(chunk, hash);
|
67
|
+
}
|
68
|
+
|
69
|
+
for (const chunkA of chunks) {
|
70
|
+
const chunkAHash =
|
71
|
+
/** @type {number} */
|
72
|
+
(chunkModulesHash.get(chunkA));
|
73
|
+
const chunkAModulesCount = chunkGraph.getNumberOfChunkModules(chunkA);
|
74
|
+
if (chunkAModulesCount === 0) continue;
|
75
|
+
let bestModule;
|
76
|
+
for (const module of chunkGraph.getChunkModulesIterable(chunkA)) {
|
77
|
+
if (
|
78
|
+
bestModule === undefined ||
|
79
|
+
chunkGraph.getNumberOfModuleChunks(bestModule) >
|
80
|
+
chunkGraph.getNumberOfModuleChunks(module)
|
81
|
+
)
|
82
|
+
bestModule = module;
|
70
83
|
}
|
84
|
+
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
|
85
|
+
/** @type {Module} */ (bestModule)
|
86
|
+
)) {
|
87
|
+
// as we iterate the same iterables twice
|
88
|
+
// skip if we find ourselves
|
89
|
+
if (chunkA === chunkB) continue;
|
71
90
|
|
72
|
-
|
73
|
-
|
91
|
+
const chunkBModulesCount =
|
92
|
+
chunkGraph.getNumberOfChunkModules(chunkB);
|
93
|
+
|
94
|
+
// ids for empty chunks are not included
|
95
|
+
if (chunkBModulesCount === 0) continue;
|
96
|
+
|
97
|
+
// instead of swapping A and B just bail
|
98
|
+
// as we loop twice the current A will be B and B then A
|
99
|
+
if (chunkAModulesCount > chunkBModulesCount) continue;
|
100
|
+
|
101
|
+
// is chunkA in chunkB?
|
102
|
+
|
103
|
+
// we do a cheap check for the hash value
|
104
|
+
const chunkBHash =
|
74
105
|
/** @type {number} */
|
75
|
-
(chunkModulesHash.get(
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
if (
|
82
|
-
bestModule === undefined ||
|
83
|
-
chunkGraph.getNumberOfModuleChunks(bestModule) >
|
84
|
-
chunkGraph.getNumberOfModuleChunks(module)
|
85
|
-
)
|
86
|
-
bestModule = module;
|
87
|
-
}
|
88
|
-
loopB: for (const chunkB of chunkGraph.getModuleChunksIterable(
|
89
|
-
/** @type {Module} */ (bestModule)
|
90
|
-
)) {
|
91
|
-
// as we iterate the same iterables twice
|
92
|
-
// skip if we find ourselves
|
93
|
-
if (chunkA === chunkB) continue;
|
94
|
-
|
95
|
-
const chunkBModulesCount =
|
96
|
-
chunkGraph.getNumberOfChunkModules(chunkB);
|
97
|
-
|
98
|
-
// ids for empty chunks are not included
|
99
|
-
if (chunkBModulesCount === 0) continue;
|
100
|
-
|
101
|
-
// instead of swapping A and B just bail
|
102
|
-
// as we loop twice the current A will be B and B then A
|
103
|
-
if (chunkAModulesCount > chunkBModulesCount) continue;
|
104
|
-
|
105
|
-
// is chunkA in chunkB?
|
106
|
-
|
107
|
-
// we do a cheap check for the hash value
|
108
|
-
const chunkBHash =
|
109
|
-
/** @type {number} */
|
110
|
-
(chunkModulesHash.get(chunkB));
|
111
|
-
if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
|
112
|
-
|
113
|
-
// compare all modules
|
114
|
-
for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
|
115
|
-
if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
|
116
|
-
}
|
117
|
-
|
118
|
-
/** @type {ChunkId[]} */
|
119
|
-
(chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
|
120
|
-
// https://github.com/webpack/webpack/issues/18837
|
121
|
-
/** @type {ChunkId[]} */
|
122
|
-
(chunkB.ids).sort(compareIds);
|
106
|
+
(chunkModulesHash.get(chunkB));
|
107
|
+
if ((chunkBHash & chunkAHash) !== chunkAHash) continue;
|
108
|
+
|
109
|
+
// compare all modules
|
110
|
+
for (const m of chunkGraph.getChunkModulesIterable(chunkA)) {
|
111
|
+
if (!chunkGraph.isModuleInChunk(m, chunkB)) continue loopB;
|
123
112
|
}
|
113
|
+
|
114
|
+
/** @type {ChunkId[]} */
|
115
|
+
(chunkB.ids).push(/** @type {ChunkId} */ (chunkA.id));
|
116
|
+
// https://github.com/webpack/webpack/issues/18837
|
117
|
+
/** @type {ChunkId[]} */
|
118
|
+
(chunkB.ids).sort(compareIds);
|
124
119
|
}
|
125
120
|
}
|
126
|
-
);
|
121
|
+
});
|
127
122
|
});
|
128
123
|
}
|
129
124
|
}
|
@@ -51,6 +51,8 @@ const addToSetMap = (map, key, value) => {
|
|
51
51
|
}
|
52
52
|
};
|
53
53
|
|
54
|
+
const PLUGIN_NAME = "LimitChunkCountPlugin";
|
55
|
+
|
54
56
|
class LimitChunkCountPlugin {
|
55
57
|
/**
|
56
58
|
* @param {LimitChunkCountPluginOptions=} options options object
|
@@ -66,10 +68,10 @@ class LimitChunkCountPlugin {
|
|
66
68
|
*/
|
67
69
|
apply(compiler) {
|
68
70
|
const options = this.options;
|
69
|
-
compiler.hooks.compilation.tap(
|
71
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
70
72
|
compilation.hooks.optimizeChunks.tap(
|
71
73
|
{
|
72
|
-
name:
|
74
|
+
name: PLUGIN_NAME,
|
73
75
|
stage: STAGE_ADVANCED
|
74
76
|
},
|
75
77
|
chunks => {
|
@@ -142,6 +142,8 @@ const mangleExportsInfo = (deterministic, exportsInfo, isNamespace) => {
|
|
142
142
|
}
|
143
143
|
};
|
144
144
|
|
145
|
+
const PLUGIN_NAME = "MangleExportsPlugin";
|
146
|
+
|
145
147
|
class MangleExportsPlugin {
|
146
148
|
/**
|
147
149
|
* @param {boolean} deterministic use deterministic names
|
@@ -157,24 +159,21 @@ class MangleExportsPlugin {
|
|
157
159
|
*/
|
158
160
|
apply(compiler) {
|
159
161
|
const { _deterministic: deterministic } = this;
|
160
|
-
compiler.hooks.compilation.tap(
|
162
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
161
163
|
const moduleGraph = compilation.moduleGraph;
|
162
|
-
compilation.hooks.optimizeCodeGeneration.tap(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
const exportsInfo = moduleGraph.getExportsInfo(module);
|
174
|
-
mangleExportsInfo(deterministic, exportsInfo, isNamespace);
|
175
|
-
}
|
164
|
+
compilation.hooks.optimizeCodeGeneration.tap(PLUGIN_NAME, modules => {
|
165
|
+
if (compilation.moduleMemCaches) {
|
166
|
+
throw new Error(
|
167
|
+
"optimization.mangleExports can't be used with cacheUnaffected as export mangling is a global effect"
|
168
|
+
);
|
169
|
+
}
|
170
|
+
for (const module of modules) {
|
171
|
+
const isNamespace =
|
172
|
+
module.buildMeta && module.buildMeta.exportsType === "namespace";
|
173
|
+
const exportsInfo = moduleGraph.getExportsInfo(module);
|
174
|
+
mangleExportsInfo(deterministic, exportsInfo, isNamespace);
|
176
175
|
}
|
177
|
-
);
|
176
|
+
});
|
178
177
|
});
|
179
178
|
}
|
180
179
|
}
|
@@ -21,6 +21,8 @@ const validate = createSchemaValidation(
|
|
21
21
|
}
|
22
22
|
);
|
23
23
|
|
24
|
+
const PLUGIN_NAME = "MinChunkSizePlugin";
|
25
|
+
|
24
26
|
class MinChunkSizePlugin {
|
25
27
|
/**
|
26
28
|
* @param {MinChunkSizePluginOptions} options options object
|
@@ -38,10 +40,10 @@ class MinChunkSizePlugin {
|
|
38
40
|
apply(compiler) {
|
39
41
|
const options = this.options;
|
40
42
|
const minChunkSize = options.minChunkSize;
|
41
|
-
compiler.hooks.compilation.tap(
|
43
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
42
44
|
compilation.hooks.optimizeChunks.tap(
|
43
45
|
{
|
44
|
-
name:
|
46
|
+
name: PLUGIN_NAME,
|
45
47
|
stage: STAGE_ADVANCED
|
46
48
|
},
|
47
49
|
chunks => {
|
@@ -48,6 +48,8 @@ const ConcatenatedModule = require("./ConcatenatedModule");
|
|
48
48
|
*/
|
49
49
|
const formatBailoutReason = msg => `ModuleConcatenation bailout: ${msg}`;
|
50
50
|
|
51
|
+
const PLUGIN_NAME = "ModuleConcatenationPlugin";
|
52
|
+
|
51
53
|
class ModuleConcatenationPlugin {
|
52
54
|
/**
|
53
55
|
* Apply the plugin
|
@@ -56,7 +58,7 @@ class ModuleConcatenationPlugin {
|
|
56
58
|
*/
|
57
59
|
apply(compiler) {
|
58
60
|
const { _backCompat: backCompat } = compiler;
|
59
|
-
compiler.hooks.compilation.tap(
|
61
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
60
62
|
if (compilation.moduleMemCaches) {
|
61
63
|
throw new Error(
|
62
64
|
"optimization.concatenateModules can't be used with cacheUnaffected as module concatenation is a global effect"
|
@@ -133,7 +135,7 @@ class ModuleConcatenationPlugin {
|
|
133
135
|
|
134
136
|
compilation.hooks.optimizeChunkModules.tapAsync(
|
135
137
|
{
|
136
|
-
name:
|
138
|
+
name: PLUGIN_NAME,
|
137
139
|
stage: STAGE_DEFAULT
|
138
140
|
},
|
139
141
|
(allChunks, modules, callback) => {
|
@@ -113,6 +113,8 @@ const compilationHooksMap = new WeakMap();
|
|
113
113
|
* @property {string=} hashDigest the hash digest to use
|
114
114
|
*/
|
115
115
|
|
116
|
+
const PLUGIN_NAME = "RealContentHashPlugin";
|
117
|
+
|
116
118
|
class RealContentHashPlugin {
|
117
119
|
/**
|
118
120
|
* @param {Compilation} compilation the compilation
|
@@ -148,7 +150,7 @@ class RealContentHashPlugin {
|
|
148
150
|
* @returns {void}
|
149
151
|
*/
|
150
152
|
apply(compiler) {
|
151
|
-
compiler.hooks.compilation.tap(
|
153
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
152
154
|
const cacheAnalyse = compilation.getCache(
|
153
155
|
"RealContentHashPlugin|analyse"
|
154
156
|
);
|
@@ -158,7 +160,7 @@ class RealContentHashPlugin {
|
|
158
160
|
const hooks = RealContentHashPlugin.getCompilationHooks(compilation);
|
159
161
|
compilation.hooks.processAssets.tapPromise(
|
160
162
|
{
|
161
|
-
name:
|
163
|
+
name: PLUGIN_NAME,
|
162
164
|
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_HASH
|
163
165
|
},
|
164
166
|
async () => {
|
@@ -10,6 +10,8 @@ const { STAGE_BASIC, STAGE_ADVANCED } = require("../OptimizationStages");
|
|
10
10
|
/** @typedef {import("../Chunk")} Chunk */
|
11
11
|
/** @typedef {import("../Compiler")} Compiler */
|
12
12
|
|
13
|
+
const PLUGIN_NAME = "RemoveEmptyChunksPlugin";
|
14
|
+
|
13
15
|
class RemoveEmptyChunksPlugin {
|
14
16
|
/**
|
15
17
|
* Apply the plugin
|
@@ -17,7 +19,7 @@ class RemoveEmptyChunksPlugin {
|
|
17
19
|
* @returns {void}
|
18
20
|
*/
|
19
21
|
apply(compiler) {
|
20
|
-
compiler.hooks.compilation.tap(
|
22
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
21
23
|
/**
|
22
24
|
* @param {Iterable<Chunk>} chunks the chunks array
|
23
25
|
* @returns {void}
|
@@ -39,14 +41,14 @@ class RemoveEmptyChunksPlugin {
|
|
39
41
|
// TODO do it once
|
40
42
|
compilation.hooks.optimizeChunks.tap(
|
41
43
|
{
|
42
|
-
name:
|
44
|
+
name: PLUGIN_NAME,
|
43
45
|
stage: STAGE_BASIC
|
44
46
|
},
|
45
47
|
handler
|
46
48
|
);
|
47
49
|
compilation.hooks.optimizeChunks.tap(
|
48
50
|
{
|
49
|
-
name:
|
51
|
+
name: PLUGIN_NAME,
|
50
52
|
stage: STAGE_ADVANCED
|
51
53
|
},
|
52
54
|
handler
|
@@ -59,13 +59,15 @@ function* getModulesFromMask(mask, ordinalModules) {
|
|
59
59
|
}
|
60
60
|
}
|
61
61
|
|
62
|
+
const PLUGIN_NAME = "RemoveParentModulesPlugin";
|
63
|
+
|
62
64
|
class RemoveParentModulesPlugin {
|
63
65
|
/**
|
64
66
|
* @param {Compiler} compiler the compiler
|
65
67
|
* @returns {void}
|
66
68
|
*/
|
67
69
|
apply(compiler) {
|
68
|
-
compiler.hooks.compilation.tap(
|
70
|
+
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
69
71
|
/**
|
70
72
|
* @param {Iterable<Chunk>} chunks the chunks
|
71
73
|
* @param {ChunkGroup[]} chunkGroups the chunk groups
|
@@ -193,7 +195,7 @@ class RemoveParentModulesPlugin {
|
|
193
195
|
};
|
194
196
|
compilation.hooks.optimizeChunks.tap(
|
195
197
|
{
|
196
|
-
name:
|
198
|
+
name: PLUGIN_NAME,
|
197
199
|
stage: STAGE_BASIC
|
198
200
|
},
|
199
201
|
handler
|
@@ -9,6 +9,8 @@
|
|
9
9
|
/** @typedef {import("../Compiler")} Compiler */
|
10
10
|
/** @typedef {import("../Entrypoint")} Entrypoint */
|
11
11
|
|
12
|
+
const PLUGIN_NAME = "RuntimeChunkPlugin";
|
13
|
+
|
12
14
|
class RuntimeChunkPlugin {
|
13
15
|
/**
|
14
16
|
* @param {{ name?: (entrypoint: { name: string }) => string }} options options
|
@@ -30,26 +32,23 @@ class RuntimeChunkPlugin {
|
|
30
32
|
* @returns {void}
|
31
33
|
*/
|
32
34
|
apply(compiler) {
|
33
|
-
compiler.hooks.thisCompilation.tap(
|
34
|
-
compilation.hooks.addEntry.tap(
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
if (typeof name === "function") {
|
47
|
-
name = name({ name: entryName });
|
48
|
-
}
|
49
|
-
data.options.runtime = name;
|
35
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
36
|
+
compilation.hooks.addEntry.tap(PLUGIN_NAME, (_, { name: entryName }) => {
|
37
|
+
if (entryName === undefined) return;
|
38
|
+
const data =
|
39
|
+
/** @type {EntryData} */
|
40
|
+
(compilation.entries.get(entryName));
|
41
|
+
if (data.options.runtime === undefined && !data.options.dependOn) {
|
42
|
+
// Determine runtime chunk name
|
43
|
+
let name =
|
44
|
+
/** @type {string | ((entrypoint: { name: string }) => string)} */
|
45
|
+
(this.options.name);
|
46
|
+
if (typeof name === "function") {
|
47
|
+
name = name({ name: entryName });
|
50
48
|
}
|
49
|
+
data.options.runtime = name;
|
51
50
|
}
|
52
|
-
);
|
51
|
+
});
|
53
52
|
});
|
54
53
|
}
|
55
54
|
}
|
@@ -26,6 +26,7 @@ const MinMaxSizeWarning = require("./MinMaxSizeWarning");
|
|
26
26
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksOptions} OptimizationSplitChunksOptions */
|
27
27
|
/** @typedef {import("../../declarations/WebpackOptions").OptimizationSplitChunksSizes} OptimizationSplitChunksSizes */
|
28
28
|
/** @typedef {import("../../declarations/WebpackOptions").Output} OutputOptions */
|
29
|
+
/** @typedef {import("../Chunk").ChunkName} ChunkName */
|
29
30
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
30
31
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
31
32
|
/** @typedef {import("../Compiler")} Compiler */
|
@@ -630,6 +631,8 @@ const createCacheGroupSource = (options, key, defaultSizeTypes) => {
|
|
630
631
|
};
|
631
632
|
};
|
632
633
|
|
634
|
+
const PLUGIN_NAME = "SplitChunksPlugin";
|
635
|
+
|
633
636
|
module.exports = class SplitChunksPlugin {
|
634
637
|
/**
|
635
638
|
* @param {OptimizationSplitChunksOptions=} options plugin options
|
@@ -821,15 +824,15 @@ module.exports = class SplitChunksPlugin {
|
|
821
824
|
compiler.context,
|
822
825
|
compiler.root
|
823
826
|
);
|
824
|
-
compiler.hooks.thisCompilation.tap(
|
825
|
-
const logger = compilation.getLogger(
|
827
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
828
|
+
const logger = compilation.getLogger(`webpack.${PLUGIN_NAME}`);
|
826
829
|
let alreadyOptimized = false;
|
827
|
-
compilation.hooks.unseal.tap(
|
830
|
+
compilation.hooks.unseal.tap(PLUGIN_NAME, () => {
|
828
831
|
alreadyOptimized = false;
|
829
832
|
});
|
830
833
|
compilation.hooks.optimizeChunks.tap(
|
831
834
|
{
|
832
|
-
name:
|
835
|
+
name: PLUGIN_NAME,
|
833
836
|
stage: STAGE_ADVANCED
|
834
837
|
},
|
835
838
|
chunks => {
|
@@ -1170,7 +1173,7 @@ module.exports = class SplitChunksPlugin {
|
|
1170
1173
|
alreadyReportedErrors.add(name);
|
1171
1174
|
compilation.errors.push(
|
1172
1175
|
new WebpackError(
|
1173
|
-
|
1176
|
+
`${PLUGIN_NAME}\n` +
|
1174
1177
|
`Cache group "${cacheGroup.key}" conflicts with existing chunk.\n` +
|
1175
1178
|
`Both have the same name "${name}" and existing chunk is not a parent of the selected modules.\n` +
|
1176
1179
|
"Use a different name for the cache group or make sure that the existing chunk is a parent (e. g. via dependOn).\n" +
|
@@ -1387,7 +1390,7 @@ module.exports = class SplitChunksPlugin {
|
|
1387
1390
|
const item = /** @type {ChunksInfoItem} */ (bestEntry);
|
1388
1391
|
chunksInfoMap.delete(/** @type {string} */ (bestEntryKey));
|
1389
1392
|
|
1390
|
-
/** @type {
|
1393
|
+
/** @type {ChunkName | undefined} */
|
1391
1394
|
let chunkName = item.name;
|
1392
1395
|
// Variable for the new chunk (lazy created)
|
1393
1396
|
/** @type {Chunk | undefined} */
|
@@ -41,6 +41,8 @@ const isOverSizeLimitSet = new WeakSet();
|
|
41
41
|
*/
|
42
42
|
const excludeSourceMap = (name, source, info) => !info.development;
|
43
43
|
|
44
|
+
const PLUGIN_NAME = "SizeLimitsPlugin";
|
45
|
+
|
44
46
|
module.exports = class SizeLimitsPlugin {
|
45
47
|
/**
|
46
48
|
* @param {PerformanceOptions} options the plugin options
|
@@ -71,7 +73,7 @@ module.exports = class SizeLimitsPlugin {
|
|
71
73
|
const hints = this.hints;
|
72
74
|
const assetFilter = this.assetFilter || excludeSourceMap;
|
73
75
|
|
74
|
-
compiler.hooks.afterEmit.tap(
|
76
|
+
compiler.hooks.afterEmit.tap(PLUGIN_NAME, compilation => {
|
75
77
|
/** @type {WebpackError[]} */
|
76
78
|
const warnings = [];
|
77
79
|
|