This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
57 lines (44 loc) · 1.44 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
48
49
50
51
52
53
54
55
56
57
'use strict';
const Filter = require('broccoli-persistent-filter');
const postcss = require('postcss');
const autoprefixer = require('autoprefixer');
function AutoprefixerFilter(inputTree, _options) {
const options = _options || {};
if (!(this instanceof AutoprefixerFilter)) {
return new AutoprefixerFilter(inputTree, _options);
}
Filter.call(this, inputTree, options);
this.inputTree = inputTree;
this.options = options;
}
AutoprefixerFilter.prototype = Object.create(Filter.prototype);
AutoprefixerFilter.prototype.constructor = AutoprefixerFilter;
AutoprefixerFilter.prototype.extensions = ['css'];
AutoprefixerFilter.prototype.targetExtension = 'css';
AutoprefixerFilter.prototype.processString = function (str, relativePath) {
const opts = Object.assign({
from: relativePath,
to: relativePath
}, this.options);
// Support explicit override of inline sourcemaps
if (opts.sourcemap !== null || opts.sourcemap !== undefined) {
opts.map = opts.sourcemap ? 'inline' : false;
}
return postcss(autoprefixer(opts))
.process(str, opts)
.then(result => {
const warnings = result.warnings();
if (warnings.length > 0) {
console.error(warnings.join('\n'));
}
return result.css;
})
.catch(err => {
if (err.name === 'CssSyntaxError') {
// TODO: Find a way to hide the stack so to adhere to the PostCSS guidelines
err.message += err.showSourceCode();
}
throw err;
});
};
module.exports = AutoprefixerFilter;