路泰科技体检小程序UI设计新版本
1
wwl
2025-08-06 964dbbb27c892433563793eeec2aa321226860d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    MIT License http://www.opensource.org/licenses/mit-license.php
    Author Florent Cailhol @ooflorent
*/
 
"use strict";
 
const { compareChunksNatural } = require("../util/comparators");
const {
    assignDeterministicIds,
    getFullChunkName,
    getUsedChunkIds
} = require("./IdHelpers");
 
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
 
/**
 * @typedef {object} DeterministicChunkIdsPluginOptions
 * @property {string=} context context for ids
 * @property {number=} maxLength maximum length of ids
 */
 
const PLUGIN_NAME = "DeterministicChunkIdsPlugin";
 
class DeterministicChunkIdsPlugin {
    /**
     * @param {DeterministicChunkIdsPluginOptions=} options options
     */
    constructor(options = {}) {
        this.options = options;
    }
 
    /**
     * Apply the plugin
     * @param {Compiler} compiler the compiler instance
     * @returns {void}
     */
    apply(compiler) {
        compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
            compilation.hooks.chunkIds.tap(PLUGIN_NAME, (chunks) => {
                const chunkGraph = compilation.chunkGraph;
                const context = this.options.context
                    ? this.options.context
                    : compiler.context;
                const maxLength = this.options.maxLength || 3;
 
                const compareNatural = compareChunksNatural(chunkGraph);
 
                const usedIds = getUsedChunkIds(compilation);
                assignDeterministicIds(
                    [...chunks].filter((chunk) => chunk.id === null),
                    (chunk) =>
                        getFullChunkName(chunk, chunkGraph, context, compiler.root),
                    compareNatural,
                    (chunk, id) => {
                        const size = usedIds.size;
                        usedIds.add(`${id}`);
                        if (size === usedIds.size) return false;
                        chunk.id = id;
                        chunk.ids = [id];
                        return true;
                    },
                    [10 ** maxLength],
                    10,
                    usedIds.size
                );
            });
        });
    }
}
 
module.exports = DeterministicChunkIdsPlugin;