webpack/lib/WarnCaseSensitiveModulesPlu...

34 lines
976 B
JavaScript
Raw Normal View History

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
"use strict";
const CaseSensitiveModulesWarning = require("./CaseSensitiveModulesWarning");
class WarnCaseSensitiveModulesPlugin {
apply(compiler) {
2017-12-06 22:01:25 +08:00
compiler.hooks.compilation.tap("WarnCaseSensitiveModulesPlugin", (compilation) => {
compilation.hooks.seal.tap("WarnCaseSensitiveModulesPlugin", () => {
2017-11-06 23:41:26 +08:00
const moduleWithoutCase = new Map();
2018-01-22 20:52:43 +08:00
for(const module of compilation.modules) {
const identifier = module.identifier().toLowerCase();
2017-11-06 23:41:26 +08:00
const array = moduleWithoutCase.get(identifier);
if(array) {
array.push(module);
} else {
2017-11-06 23:41:26 +08:00
moduleWithoutCase.set(identifier, [module]);
}
2018-01-22 20:52:43 +08:00
}
2017-11-06 23:41:26 +08:00
for(const pair of moduleWithoutCase) {
const array = pair[1];
if(array.length > 1)
compilation.warnings.push(new CaseSensitiveModulesWarning(array));
}
});
});
}
}
module.exports = WarnCaseSensitiveModulesPlugin;