source: trip-planner-front/node_modules/webpack/lib/ids/DeterministicModuleIdsPlugin.js@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

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