-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 1.05 KB
/
index.js
File metadata and controls
36 lines (28 loc) · 1.05 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
'use strict';
var RawModule = require('webpack/lib/RawModule');
function EmptyModulePlugin(resourceRegExp, source) {
this.resourceRegExp = resourceRegExp;
this.source = source || '/* empty */';
}
module.exports = EmptyModulePlugin;
EmptyModulePlugin.prototype.apply = function (compiler) {
compiler.plugin('normal-module-factory', function (nmf) {
nmf.plugin('resolver', function (resolver) {
return function (data, callback) {
var request = data.request;
if (this.resourceRegExp.test(request)) {
var source = this.source;
if (typeof this.source === 'function') {
source = this.source(request);
}
return callback(null, new RawModule(
source,
'empty ' + context + ' ' + request,
request + ' (empty)'
));
}
return resolver(data, callback);
};
});
});
};