Implement JQHTML function cache ID system and fix bundle compilation Implement underscore prefix for system tables Fix JS syntax linter to support decorators and grant exception to Task system SPA: Update planning docs and wishlists with remaining features SPA: Document Navigation API abandonment and future enhancements Implement SPA browser integration with History API (Phase 1) Convert contacts view page to SPA action Convert clients pages to SPA actions and document conversion procedure SPA: Merge GET parameters and update documentation Implement SPA route URL generation in JavaScript and PHP Implement SPA bootstrap controller architecture Add SPA routing manual page (rsx:man spa) Add SPA routing documentation to CLAUDE.md Phase 4 Complete: Client-side SPA routing implementation Update get_routes() consumers for unified route structure Complete SPA Phase 3: PHP-side route type detection and is_spa flag Restore unified routes structure and Manifest_Query class Refactor route indexing and add SPA infrastructure Phase 3 Complete: SPA route registration in manifest Implement SPA Phase 2: Extract router code and test decorators Rename Jqhtml_Component to Component and complete SPA foundation setup 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
119 lines
3.3 KiB
JavaScript
119 lines
3.3 KiB
JavaScript
/*
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
Author Tobias Koppers @sokra
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
|
const createSchemaValidation = require("../util/create-schema-validation");
|
|
|
|
/** @typedef {import("../../declarations/plugins/optimize/MinChunkSizePlugin").MinChunkSizePluginOptions} MinChunkSizePluginOptions */
|
|
/** @typedef {import("../Chunk")} Chunk */
|
|
/** @typedef {import("../Compiler")} Compiler */
|
|
|
|
const validate = createSchemaValidation(
|
|
require("../../schemas/plugins/optimize/MinChunkSizePlugin.check"),
|
|
() => require("../../schemas/plugins/optimize/MinChunkSizePlugin.json"),
|
|
{
|
|
name: "Min Chunk Size Plugin",
|
|
baseDataPath: "options"
|
|
}
|
|
);
|
|
|
|
const PLUGIN_NAME = "MinChunkSizePlugin";
|
|
|
|
class MinChunkSizePlugin {
|
|
/**
|
|
* @param {MinChunkSizePluginOptions} options options object
|
|
*/
|
|
constructor(options) {
|
|
validate(options);
|
|
this.options = options;
|
|
}
|
|
|
|
/**
|
|
* Apply the plugin
|
|
* @param {Compiler} compiler the compiler instance
|
|
* @returns {void}
|
|
*/
|
|
apply(compiler) {
|
|
const options = this.options;
|
|
const minChunkSize = options.minChunkSize;
|
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
compilation.hooks.optimizeChunks.tap(
|
|
{
|
|
name: PLUGIN_NAME,
|
|
stage: STAGE_ADVANCED
|
|
},
|
|
(chunks) => {
|
|
const chunkGraph = compilation.chunkGraph;
|
|
const equalOptions = {
|
|
chunkOverhead: 1,
|
|
entryChunkMultiplicator: 1
|
|
};
|
|
|
|
const chunkSizesMap = new Map();
|
|
/** @type {[Chunk, Chunk][]} */
|
|
const combinations = [];
|
|
/** @type {Chunk[]} */
|
|
const smallChunks = [];
|
|
const visitedChunks = [];
|
|
for (const a of chunks) {
|
|
// check if one of the chunks sizes is smaller than the minChunkSize
|
|
// and filter pairs that can NOT be integrated!
|
|
if (chunkGraph.getChunkSize(a, equalOptions) < minChunkSize) {
|
|
smallChunks.push(a);
|
|
for (const b of visitedChunks) {
|
|
if (chunkGraph.canChunksBeIntegrated(b, a)) {
|
|
combinations.push([b, a]);
|
|
}
|
|
}
|
|
} else {
|
|
for (const b of smallChunks) {
|
|
if (chunkGraph.canChunksBeIntegrated(b, a)) {
|
|
combinations.push([b, a]);
|
|
}
|
|
}
|
|
}
|
|
chunkSizesMap.set(a, chunkGraph.getChunkSize(a, options));
|
|
visitedChunks.push(a);
|
|
}
|
|
|
|
const sortedSizeFilteredExtendedPairCombinations = combinations
|
|
.map((pair) => {
|
|
// extend combination pairs with size and integrated size
|
|
const a = chunkSizesMap.get(pair[0]);
|
|
const b = chunkSizesMap.get(pair[1]);
|
|
const ab = chunkGraph.getIntegratedChunksSize(
|
|
pair[0],
|
|
pair[1],
|
|
options
|
|
);
|
|
/** @type {[number, number, Chunk, Chunk]} */
|
|
const extendedPair = [a + b - ab, ab, pair[0], pair[1]];
|
|
return extendedPair;
|
|
})
|
|
.sort((a, b) => {
|
|
// sadly javascript does an in place sort here
|
|
// sort by size
|
|
const diff = b[0] - a[0];
|
|
if (diff !== 0) return diff;
|
|
return a[1] - b[1];
|
|
});
|
|
|
|
if (sortedSizeFilteredExtendedPairCombinations.length === 0) return;
|
|
|
|
const pair = sortedSizeFilteredExtendedPairCombinations[0];
|
|
|
|
chunkGraph.integrateChunks(pair[2], pair[3]);
|
|
compilation.chunks.delete(pair[3]);
|
|
return true;
|
|
}
|
|
);
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = MinChunkSizePlugin;
|