-
Notifications
You must be signed in to change notification settings - Fork 25
/
index.js
56 lines (49 loc) · 1.47 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
var loaderUtils = require('loader-utils');
var autoprefixer = require('autoprefixer');
var postcss = require('postcss');
var path = require('path');
var safe = require('postcss-safe-parser');
module.exports = function (source, map) {
if (this.cacheable) {
this.cacheable();
}
var params = loaderUtils.parseQuery(this.query);
if (params.browsers && !Array.isArray(params.browsers)) {
params.browsers = params.browsers.split(',');
}
if (params.cascade === 'false') {
params.cascade = false;
}
var options = {from: path.relative(this.options.context, this.resource)};
if (params.safe) {
delete params.safe;
options.parser = safe;
}
var whitelist = {
browsers: true,
cascade: true,
add: true,
remove: true,
};
var unknownParams = [];
for (var i in params) {
if (!whitelist[i]) {
unknownParams.push(i);
}
}
if (unknownParams.length) {
var warn = unknownParams.length === 1 ?
'Autoprefixer-loader got this undocumented option: ' :
'Autoprefixer-loader got these undocumented options: ';
warn += unknownParams.join(', ');
this.emitWarning(warn);
}
if (map) {
options.map = {
prev: map,
};
}
var prefixer = autoprefixer(params);
var processed = postcss([prefixer]).process(source, options);
this.callback(null, processed.css, processed.map);
};