-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
36 lines (33 loc) · 961 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
const postcss = require('postcss')
const compileAmpCustom = require('./libs/compileAmpCustom')
const isPostCSSv8 = require('./libs/isPostCSSv8')
const PLUGIN_NAME = 'postcss-amp-custom'
module.exports = (option = {}) => {
option = Object.assign({
enableByteLimit: false
}, option || {})
if (isPostCSSv8(postcss)) {
return {
postcssPlugin: PLUGIN_NAME,
Root (root, postcss) {
postcss.result.root = compileAmpCustom(root, postcss, option)
}
}
} else {
return postcss.plugin(PLUGIN_NAME, (option) => {
return (root, result) => {
return new Promise((resolve, reject) => {
try {
const postcss = require('postcss')
const style = compileAmpCustom(root, postcss, option)
result.root = postcss.parse(style)
resolve()
} catch (error) {
reject(error)
}
})
}
})
}
}
module.exports.postcss = true