-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
31 lines (29 loc) · 797 Bytes
/
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
const path = require('path');
const apply = function(options, compiler) {
if (options == null) {
options = {};
}
var test = options.test;
if (test == null) {
return;
}
var callback = options.callback || function (filepath, source) { return source; };
var dirname = options.dirname || path.resolve(__dirname);
compiler.plugin('emit', function(compilation, done) {
for (var basename in compilation.assets) {
var filepath = path.resolve(dirname, basename);
if (test.test(filepath)) {
var asset = compilation.assets[basename];
var origFn = asset.source();
asset.source = () => callback(filepath, origFn);
asset.size = () => asset.source().length;
}
}
done();
});
};
module.exports = function(options) {
return {
apply: apply.bind(this, options)
};
};