-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
47 lines (42 loc) · 1.09 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
45
46
47
var bless = require('bless');
var RawSource = require('webpack/lib/RawSource');
var _ = require('lodash');
module.exports = function(options, pattern) {
pattern = pattern || /\.css$/;
options = options || {};
return {
apply: function(compiler) {
compiler.plugin("this-compilation", function(compilation) {
compilation.plugin("optimize-assets", function(assets, callback) {
var pending = 0;
function done(err) {
pending--;
if (err && pending >= 0) {
pending = 0;
callback(err);
} else if (pending === 0) {
callback();
}
}
Object.keys(assets)
.filter(pattern.test.bind(pattern))
.forEach(function(name) {
pending++;
new bless.Parser({ output: name, options : options })
.parse(assets[name].source(), function(err, files) {
if (err) {
done(err);
return;
}
delete assets[name];
files.forEach(function(file) {
assets[file.filename] = new RawSource(file.content);
});
done();
});
});
});
});
}
};
};