index.js
1.72 KB
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
58
59
60
61
62
63
64
65
66
67
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _postcss = require('postcss');
var _postcss2 = _interopRequireDefault(_postcss);
var _browserslist = require('browserslist');
var _browserslist2 = _interopRequireDefault(_browserslist);
var _plugins = require('./plugins');
var _plugins2 = _interopRequireDefault(_plugins);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const stylehacks = _postcss2.default.plugin('stylehacks', (opts = {}) => {
return (css, result) => {
const resultOpts = result.opts || {};
const browsers = (0, _browserslist2.default)(null, {
stats: resultOpts.stats,
path: __dirname,
env: resultOpts.env
});
const processors = _plugins2.default.reduce((list, Plugin) => {
const hack = new Plugin(result);
const applied = browsers.some(browser => {
return hack.targets.some(target => browser === target);
});
if (applied) {
return list;
}
return [...list, hack];
}, []);
css.walk(node => {
processors.forEach(proc => {
if (!~proc.nodeTypes.indexOf(node.type)) {
return;
}
if (opts.lint) {
return proc.detectAndWarn(node);
}
return proc.detectAndResolve(node);
});
});
};
});
stylehacks.detect = node => {
return _plugins2.default.some(Plugin => {
const hack = new Plugin();
return hack.any(node);
});
};
exports.default = stylehacks;
module.exports = exports['default'];