forked from stackcss/sheetify-postcss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (35 loc) · 904 Bytes
/
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
const defined = require('defined')
const postcss = require('postcss')
const extend = require('xtend')
const resolve = require('resolve')
module.exports = transform
function transform (filename, source, options, done) {
options = defined(options, {})
const basedir = options.basedir
const plugins = defined(options.plugins, [])
.map(plugin => {
if (typeof plugin === 'string') {
plugin = [ plugin ]
}
return {
path: resolve.sync(plugin[0], { basedir }),
options: plugin[1]
}
})
.map(plugin => require(plugin.path)(plugin.options))
postcss(plugins)
.process(source, extend({
sourcemap: true,
from: filename,
messages: {
browser: true,
console: false
}
}, options))
.then(function (result) {
done(null, result.css)
})
.catch(function (err) {
done(err)
})
}