NaturalModuleIdsPlugin.js
1.0 KB
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
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Florent Cailhol @ooflorent
*/
"use strict";
const {
compareModulesByPreOrderIndexOrIdentifier
} = require("../util/comparators");
const {
assignAscendingModuleIds,
getUsedModuleIdsAndModules
} = require("./IdHelpers");
/** @typedef {import("../Compiler")} Compiler */
/** @typedef {import("../Module")} Module */
class NaturalModuleIdsPlugin {
/**
* Apply the plugin
* @param {Compiler} compiler the compiler instance
* @returns {void}
*/
apply(compiler) {
compiler.hooks.compilation.tap("NaturalModuleIdsPlugin", compilation => {
compilation.hooks.moduleIds.tap("NaturalModuleIdsPlugin", modules => {
const [usedIds, modulesInNaturalOrder] =
getUsedModuleIdsAndModules(compilation);
modulesInNaturalOrder.sort(
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
);
assignAscendingModuleIds(usedIds, modulesInNaturalOrder, compilation);
});
});
}
}
module.exports = NaturalModuleIdsPlugin;