This repository has been archived by the owner on Nov 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (62 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
71
72
73
74
75
76
77
var _defaults = require('lodash').defaults
var postcss = require('postcss')
var atImport = require('postcss-import')
var customMedia = require('postcss-custom-media')
var customProperties = require('postcss-custom-properties')
var calc = require('postcss-calc')
var colorFunction = require('postcss-color-function')
var removeMutations = require('postcss-remove-mutations')
var removeIds = require('./lib/remove-ids')
var bassmods = require('basscss').modules
module.exports = postcss.plugin('postcss-basscss', function (opts) {
var bassmodsObj = {}
bassmods.forEach(function (key) {
bassmodsObj[key] = true
})
opts = opts || {}
opts = _defaults(opts, {
modules: bassmodsObj,
import: {},
customMedia: {},
customProperties: {},
calc: {},
colorFunction: {},
raw: false,
immutable: true,
removeIds: true
})
var basscssSource = []
Object.keys(opts.modules).forEach(function (key) {
if (opts.modules[key]) {
basscssSource.push('@import "' + key + '";')
}
})
var processor = postcss([atImport(opts.import)])
if (!opts.raw) {
processor
.use(customMedia(opts.customMedia))
.use(customProperties(opts.customProperties))
.use(calc(opts.calc))
.use(colorFunction(opts.colorFunction))
}
return function (root, result) {
var basscss = processor
.process(basscssSource.join('\n'))
.root
if (opts.immutable) {
root = postcss()
.use(removeMutations({
immutables: basscss
}))
.process(root)
.root
}
if (opts.removeIds) {
root = postcss()
.use(removeIds())
.process(root)
.root
}
root.prepend(basscss)
}
})