-
Notifications
You must be signed in to change notification settings - Fork 12
/
index.js
executable file
·70 lines (54 loc) · 1.69 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
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict'
const postcss = require('postcss')
const cssnano = require('cssnano')
const queries = require('css-mqpacker')
const perfect = require('perfectionist')
const prefixer = require('autoprefixer')
const atImport = require('postcss-import')
const media = require('postcss-custom-media')
const vars = require('postcss-css-variables')
const extend = require('postcss-extend-rule')
const conditionals = require('postcss-conditionals')
const rmComments = require('postcss-discard-comments')
const classRepeat = require('postcss-class-repeat')
const calc = require('postcss-calc')
const rtl = require('postcss-rtl')
const getPlugins = function (options) {
options = options || {}
const perfectionistOptions = options.perfectionist || {
format: 'compact',
trimTrailingZeros: false
}
const atImportOptions = options.atImport || {}
const plugins = [
atImport(atImportOptions), conditionals(), media(), queries(), perfect(perfectionistOptions),
prefixer(), extend()
]
if (!options.preserveVariables) {
plugins.splice(1, 0, calc())
plugins.splice(1, 0, vars())
}
if (options.minify) {
plugins.push(cssnano())
plugins.push(rmComments())
}
if (options.repeat) {
let repeatNum = parseInt(options.repeat) || 4
if (repeatNum < 2) {
repeatNum = 4
}
plugins.push(classRepeat({ repeat: repeatNum }))
}
if (options.rtl) {
plugins.push(rtl())
}
if (options.plugins) {
options.plugins.forEach(plugin => plugins.push(plugin))
}
return plugins
}
module.exports = function tachyonsBuild (css, options) {
const plugins = getPlugins(options)
return postcss(plugins).process(css, options)
}
module.exports.getPlugins = getPlugins