From 9bce51f651aad297ef9eb6df832bfdaf1de05d84 Mon Sep 17 00:00:00 2001
From: WXL <wl_5969728@163.com>
Date: 星期三, 22 四月 2026 14:27:54 +0800
Subject: [PATCH] 青岛推送
---
node_modules/webpack/lib/optimize/LimitChunkCountPlugin.js | 54 ++++++++++++++++++++++++++++++++++--------------------
1 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/node_modules/webpack/lib/optimize/LimitChunkCountPlugin.js b/node_modules/webpack/lib/optimize/LimitChunkCountPlugin.js
index 74ed248..1717268 100644
--- a/node_modules/webpack/lib/optimize/LimitChunkCountPlugin.js
+++ b/node_modules/webpack/lib/optimize/LimitChunkCountPlugin.js
@@ -8,22 +8,13 @@
const { STAGE_ADVANCED } = require("../OptimizationStages");
const LazyBucketSortedSet = require("../util/LazyBucketSortedSet");
const { compareChunks } = require("../util/comparators");
-const createSchemaValidation = require("../util/create-schema-validation");
/** @typedef {import("../../declarations/plugins/optimize/LimitChunkCountPlugin").LimitChunkCountPluginOptions} LimitChunkCountPluginOptions */
/** @typedef {import("../Chunk")} Chunk */
/** @typedef {import("../Compiler")} Compiler */
-const validate = createSchemaValidation(
- require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check"),
- () => require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
- {
- name: "Limit Chunk Count Plugin",
- baseDataPath: "options"
- }
-);
-
/**
+ * Defines the chunk combination type used by this module.
* @typedef {object} ChunkCombination
* @property {boolean} deleted this is set to true when combination was removed
* @property {number} sizeDiff
@@ -37,6 +28,7 @@
*/
/**
+ * Adds the provided map to this object.
* @template K, V
* @param {Map<K, Set<V>>} map map
* @param {K} key key
@@ -55,19 +47,36 @@
class LimitChunkCountPlugin {
/**
+ * Creates an instance of LimitChunkCountPlugin.
* @param {LimitChunkCountPluginOptions=} options options object
*/
- constructor(options) {
- validate(options);
- this.options = /** @type {LimitChunkCountPluginOptions} */ (options);
+ constructor(options = { maxChunks: 1 }) {
+ /** @type {LimitChunkCountPluginOptions} */
+ this.options = options;
}
/**
+ * Applies the plugin by registering its hooks on the compiler.
* @param {Compiler} compiler the webpack compiler
* @returns {void}
*/
apply(compiler) {
- const options = this.options;
+ compiler.hooks.validate.tap(PLUGIN_NAME, () => {
+ compiler.validate(
+ () =>
+ require("../../schemas/plugins/optimize/LimitChunkCountPlugin.json"),
+ this.options,
+ {
+ name: "Limit Chunk Count Plugin",
+ baseDataPath: "options"
+ },
+ (options) =>
+ require("../../schemas/plugins/optimize/LimitChunkCountPlugin.check")(
+ options
+ )
+ );
+ });
+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
compilation.hooks.optimizeChunks.tap(
{
@@ -76,7 +85,7 @@
},
(chunks) => {
const chunkGraph = compilation.chunkGraph;
- const maxChunks = options.maxChunks;
+ const maxChunks = this.options.maxChunks;
if (!maxChunks) return;
if (maxChunks < 1) return;
if (compilation.chunks.size <= maxChunks) return;
@@ -100,11 +109,13 @@
// Layer 2: ordered by smallest combined size
/**
+ * Handles the stage callback for this hook.
* @param {ChunkCombination} c combination
* @returns {number} integrated size
*/
(c) => c.integratedSize,
/**
+ * Handles the callback logic for this hook.
* @param {number} a a
* @param {number} b b
* @returns {number} result
@@ -113,11 +124,13 @@
// Layer 3: ordered by position difference in orderedChunk (-> to be deterministic)
/**
+ * Handles the callback logic for this hook.
* @param {ChunkCombination} c combination
* @returns {number} position difference
*/
(c) => c.bIdx - c.aIdx,
/**
+ * Handles the callback logic for this hook.
* @param {number} a a
* @param {number} b b
* @returns {number} result
@@ -126,6 +139,7 @@
// Layer 4: ordered by position in orderedChunk (-> to be deterministic)
/**
+ * Handles the callback logic for this hook.
* @param {ChunkCombination} a a
* @param {ChunkCombination} b b
* @returns {number} result
@@ -149,11 +163,11 @@
const integratedSize = chunkGraph.getIntegratedChunksSize(
a,
b,
- options
+ this.options
);
- const aSize = chunkGraph.getChunkSize(a, options);
- const bSize = chunkGraph.getChunkSize(b, options);
+ const aSize = chunkGraph.getChunkSize(a, this.options);
+ const bSize = chunkGraph.getChunkSize(b, this.options);
/** @type {ChunkCombination} */
const c = {
deleted: false,
@@ -251,7 +265,7 @@
const newIntegratedSize = chunkGraph.getIntegratedChunksSize(
a,
combination.b,
- options
+ this.options
);
const finishUpdate = combinations.startUpdate(combination);
combination.a = a;
@@ -270,7 +284,7 @@
const newIntegratedSize = chunkGraph.getIntegratedChunksSize(
combination.a,
a,
- options
+ this.options
);
const finishUpdate = combinations.startUpdate(combination);
--
Gitblit v1.9.3