1 | 'use strict';
|
2 |
|
3 | var $postcss,
|
4 | processors,
|
5 | reporter,
|
6 | defaults,
|
7 | rucksack;
|
8 |
|
9 | $postcss = require('postcss');
|
10 |
|
11 | processors = {
|
12 | alias: require('postcss-alias'),
|
13 | responsiveType: require('postcss-responsive-type'),
|
14 | shorthandPosition: require('postcss-position'),
|
15 | quantityQueries: require('postcss-quantity-queries'),
|
16 | inputPseudo: require('postcss-input-style'),
|
17 | clearFix: require('postcss-clearfix'),
|
18 | fontPath: require('postcss-fontpath'),
|
19 | hexRGBA: require('postcss-hexrgba'),
|
20 | easings: require('postcss-easings'),
|
21 | fallbacks: require('laggard'),
|
22 | autoprefixer: require('autoprefixer')
|
23 | };
|
24 |
|
25 |
|
26 | reporter = require('postcss-reporter');
|
27 |
|
28 |
|
29 | defaults = {
|
30 | autoprefixer: false,
|
31 | fallbacks: false
|
32 | };
|
33 |
|
34 |
|
35 | rucksack = $postcss.plugin('rucksack', function(options) {
|
36 |
|
37 | var postcss = $postcss(),
|
38 | plugins = [];
|
39 |
|
40 | options = options || {};
|
41 |
|
42 | Object.keys(defaults).forEach(function(opt){
|
43 | if (!options.hasOwnProperty(opt)){
|
44 | options[opt] = defaults[opt];
|
45 | }
|
46 | });
|
47 |
|
48 | Object.keys(processors).forEach(function(feature){
|
49 | var processor = processors[feature];
|
50 |
|
51 | if (options[feature] !== false) {
|
52 | plugins.push(processor);
|
53 | }
|
54 | });
|
55 |
|
56 | plugins.push(reporter);
|
57 |
|
58 |
|
59 | plugins.forEach(function(plugin){
|
60 | postcss.use(plugin);
|
61 | });
|
62 |
|
63 | return postcss;
|
64 |
|
65 | });
|
66 |
|
67 |
|
68 | module.exports = rucksack;
|
69 |
|
70 | module.exports.process = function(css, options) {
|
71 | options = options || {};
|
72 | options.map = options.map || (options.sourcemap ? true : null);
|
73 |
|
74 | var result = $postcss([rucksack(options)]).process(css, options);
|
75 |
|
76 |
|
77 | if (options.map === null || options.map === true || options.map && options.map.inline) {
|
78 | return result.css;
|
79 | }
|
80 |
|
81 |
|
82 | return result;
|
83 |
|
84 | };
|