forked from dcousineau/force-case-sensitivity-webpack-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (39 loc) · 1.33 KB
/
index.js
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
40
41
42
43
44
/**
* Original code credit to Alexandre Kirszenberg. Only modifications made were
* to fit into newer Webpack plugin structure and publish as an npm module.
*
* @see https://gist.github.com/Morhaus/333579c2a5b4db644bd5
*/
var path = require('path');
var fs = require('fs');
var _ = require('lodash');
var reIgnore = /dev\-server|hot\-middleware/;
function ForceCaseSensitivityPlugin() {
//no-op
}
ForceCaseSensitivityPlugin.prototype.apply = function(compiler) {
compiler.plugin('normal-module-factory', function(nmf) {
nmf.plugin('after-resolve', function(data, done) {
if (reIgnore.test(data.resource)) {
done(null, data);
return;
}
var parentDir = path.dirname(data.resource);
var resourceName = path.basename(data.resource);
fs.readdir(parentDir, function(err, files) {
if (err) {
return done(err);
}
if (files.indexOf(resourceName) === -1) {
var realName = _.find(files, function(filename) {
return filename.toLowerCase() === resourceName.toLowerCase()
});
done(new Error('ForceCaseSensitivityPlugin: `' + resourceName + '` does not match the corresponding file on disk `' + realName + '`'));
return;
}
done(null, data);
});
});
});
};
module.exports = ForceCaseSensitivityPlugin;