forked from brunch/clean-css-brunch
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
35 lines (28 loc) · 896 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
32
33
34
35
'use strict';
const CleanCSS = require('clean-css');
class CleanCSSMinifier {
constructor(config) {
this.options = config && config.plugins && config.plugins.cleancss || {};
}
optimize(file) {
const data = file.data;
const path = file.path;
try {
if (this.options.ignored && this.options.ignored.test(path)) {
// ignored file path: return non minified
return Promise.resolve(data);
}
} catch (e) {
return Promise.reject(`error checking ignored files to minify ${e}`);
}
try {
const min = new CleanCSS(this.options).minify(data);
return Promise.resolve(min.styles || data);
} catch (error) {
return Promise.reject(`CSS minify failed on ${path}: ${error}`);
}
}
}
CleanCSSMinifier.prototype.brunchPlugin = true;
CleanCSSMinifier.prototype.type = 'stylesheet';
module.exports = CleanCSSMinifier;