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