You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.0 KiB
40 lines
1.0 KiB
3 years ago
|
/*
|
||
|
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;
|