feat: export `MergeDuplicateChunks` plugin

This commit is contained in:
alexander.akait 2024-11-12 19:42:30 +03:00
parent d7514b4fce
commit 0ab5b9e00c
8 changed files with 50 additions and 10 deletions

View File

@ -51,7 +51,7 @@ export interface BannerPluginOptions {
*/
raw?: boolean;
/**
* Specifies the banner.
* Specifies the stage when add a banner.
*/
stage?: number;
/**

View File

@ -443,6 +443,9 @@ module.exports = mergeExports(fn, {
get LimitChunkCountPlugin() {
return require("./optimize/LimitChunkCountPlugin");
},
get MergeDuplicateChunksPlugin() {
return require("./optimize/MergeDuplicateChunksPlugin.js");
},
get MinChunkSizePlugin() {
return require("./optimize/MinChunkSizePlugin");
},

View File

@ -6,11 +6,27 @@
"use strict";
const { STAGE_BASIC } = require("../OptimizationStages");
const createSchemaValidation = require("../util/create-schema-validation");
const { runtimeEqual } = require("../util/runtime");
/** @typedef {import("../Compiler")} Compiler */
const validate = createSchemaValidation(
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.check.js"),
() =>
require("../../schemas/plugins/optimize/MergeDuplicateChunksPlugin.json"),
{
name: "Merge Duplicate Chunks Plugin",
baseDataPath: "options"
}
);
class MergeDuplicateChunksPlugin {
constructor(options = { stage: STAGE_BASIC }) {
validate(options);
this.options = options;
}
/**
* @param {Compiler} compiler the compiler
* @returns {void}
@ -22,7 +38,7 @@ class MergeDuplicateChunksPlugin {
compilation.hooks.optimizeChunks.tap(
{
name: "MergeDuplicateChunksPlugin",
stage: STAGE_BASIC
stage: this.options.stage
},
chunks => {
const { chunkGraph, moduleGraph } = compilation;

View File

@ -90,7 +90,7 @@
"type": "boolean"
},
"stage": {
"description": "Specifies the banner.",
"description": "Specifies the stage when add a banner.",
"type": "number"
},
"test": {

View File

@ -0,0 +1,11 @@
{
"title": "MergeDuplicateChunksPluginOptions",
"type": "object",
"additionalProperties": false,
"properties": {
"stage": {
"description": "Specifies the stage for merging duplicate chunks.",
"type": "number"
}
}
}

View File

@ -4813,22 +4813,22 @@ assets by path *.wasm X KiB
asset XXXXXXXXXXXXXXXXXXXX.module.wasm X bytes [emitted] [immutable]
asset XXXXXXXXXXXXXXXXXXXX.module.wasm X bytes [emitted] [immutable]
asset XXXXXXXXXXXXXXXXXXXX.module.wasm X bytes [emitted] [immutable]
chunk (runtime: main) 573.bundle.js X bytes (javascript) X bytes (webassembly) [rendered] reused as split chunk (cache group: default)
chunk (runtime: main) 573.bundle.js X bytes (javascript) X bytes (webassembly) [rendered]
./Q_rsqrt.wasm X bytes (javascript) X bytes (webassembly) [built] [code generated]
chunk (runtime: main) 672.bundle.js X bytes (javascript) X bytes (webassembly) [rendered] reused as split chunk (cache group: default)
chunk (runtime: main) 672.bundle.js X bytes (javascript) X bytes (webassembly) [rendered]
./duff.wasm X bytes (javascript) X bytes (webassembly) [built] [code generated]
chunk (runtime: main) 787.bundle.js (id hint: vendors) X bytes [rendered] split chunk (cache group: defaultVendors)
./node_modules/env.js X bytes [built] [code generated]
chunk (runtime: main) bundle.js (main) X bytes (javascript) X KiB (runtime) [entry] [rendered]
runtime modules X KiB 11 modules
./index.js X bytes [built] [code generated]
chunk (runtime: main) 836.bundle.js X KiB (javascript) X bytes (webassembly) [rendered] reused as split chunk (cache group: default)
chunk (runtime: main) 836.bundle.js X KiB (javascript) X bytes (webassembly) [rendered]
./testFunction.wasm X bytes (javascript) X bytes (webassembly) [dependent] [built] [code generated]
./tests.js X KiB [built] [code generated]
chunk (runtime: main) 946.bundle.js X bytes (javascript) X bytes (webassembly) [rendered] reused as split chunk (cache group: default)
chunk (runtime: main) 946.bundle.js X bytes (javascript) X bytes (webassembly) [rendered]
./fact.wasm X bytes (javascript) X bytes (webassembly) [built] [code generated]
./fast-math.wasm X bytes (javascript) X bytes (webassembly) [built] [code generated]
chunk (runtime: main) 989.bundle.js X bytes (javascript) X bytes (webassembly) [rendered] reused as split chunk (cache group: default)
chunk (runtime: main) 989.bundle.js X bytes (javascript) X bytes (webassembly) [rendered]
./popcnt.wasm X bytes (javascript) X bytes (webassembly) [built] [code generated]
runtime modules X KiB 11 modules
cacheable modules X KiB (javascript) X KiB (webassembly)

View File

@ -1,4 +1,5 @@
const { ModuleFederationPlugin } = require("../../../").container;
const webpack = require("../../../");
const { ModuleFederationPlugin } = webpack.container;
const {
WEBPACK_MODULE_TYPE_PROVIDE
} = require("../../../lib/ModuleTypeConstants");
@ -70,6 +71,9 @@ module.exports = {
requiredVersion: "=1.0.0"
}
}
}),
new webpack.optimize.MergeDuplicateChunksPlugin({
stage: 10
})
],
stats: {

8
types.d.ts vendored
View File

@ -513,7 +513,7 @@ declare interface BannerPluginOptions {
raw?: boolean;
/**
* Specifies the banner.
* Specifies the stage when add a banner.
*/
stage?: number;
@ -8643,6 +8643,11 @@ declare class MemoryCachePlugin {
*/
apply(compiler: Compiler): void;
}
declare class MergeDuplicateChunksPlugin {
constructor(options?: { stage: -10 });
options: { stage: -10 };
apply(compiler: Compiler): void;
}
declare class MinChunkSizePlugin {
constructor(options: MinChunkSizePluginOptions);
options: MinChunkSizePluginOptions;
@ -16122,6 +16127,7 @@ declare namespace exports {
AggressiveMergingPlugin,
AggressiveSplittingPlugin,
LimitChunkCountPlugin,
MergeDuplicateChunksPlugin,
MinChunkSizePlugin,
ModuleConcatenationPlugin,
RealContentHashPlugin,