source: imaps-frontend/node_modules/webpack/lib/ids/DeterministicChunkIdsPlugin.js

main
Last change on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 1.9 KB
RevLine 
[79a0317]1/*
2 MIT License http://www.opensource.org/licenses/mit-license.php
3 Author Florent Cailhol @ooflorent
4*/
5
6"use strict";
7
8const { compareChunksNatural } = require("../util/comparators");
9const {
10 getFullChunkName,
11 getUsedChunkIds,
12 assignDeterministicIds
13} = require("./IdHelpers");
14
15/** @typedef {import("../Compiler")} Compiler */
16/** @typedef {import("../Module")} Module */
17
18/**
19 * @typedef {object} DeterministicChunkIdsPluginOptions
20 * @property {string=} context context for ids
21 * @property {number=} maxLength maximum length of ids
22 */
23
24class DeterministicChunkIdsPlugin {
25 /**
26 * @param {DeterministicChunkIdsPluginOptions} [options] options
27 */
28 constructor(options = {}) {
29 this.options = options;
30 }
31
32 /**
33 * Apply the plugin
34 * @param {Compiler} compiler the compiler instance
35 * @returns {void}
36 */
37 apply(compiler) {
38 compiler.hooks.compilation.tap(
39 "DeterministicChunkIdsPlugin",
40 compilation => {
41 compilation.hooks.chunkIds.tap(
42 "DeterministicChunkIdsPlugin",
43 chunks => {
44 const chunkGraph = compilation.chunkGraph;
45 const context = this.options.context
46 ? this.options.context
47 : compiler.context;
48 const maxLength = this.options.maxLength || 3;
49
50 const compareNatural = compareChunksNatural(chunkGraph);
51
52 const usedIds = getUsedChunkIds(compilation);
53 assignDeterministicIds(
54 Array.from(chunks).filter(chunk => chunk.id === null),
55 chunk =>
56 getFullChunkName(chunk, chunkGraph, context, compiler.root),
57 compareNatural,
58 (chunk, id) => {
59 const size = usedIds.size;
60 usedIds.add(`${id}`);
61 if (size === usedIds.size) return false;
62 chunk.id = id;
63 chunk.ids = [id];
64 return true;
65 },
66 [10 ** maxLength],
67 10,
68 usedIds.size
69 );
70 }
71 );
72 }
73 );
74 }
75}
76
77module.exports = DeterministicChunkIdsPlugin;
Note: See TracBrowser for help on using the repository browser.