load-postcss-config.js
1.14 KB
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
var load = require('postcss-load-config')
var loaded
function isObject (val) {
return val && typeof val === 'object'
}
module.exports = function loadPostcssConfig (loaderContext, inlineConfig) {
if (process.env.VUE_LOADER_TEST || !loaded) {
loaded = load({
webpack: loaderContext
}, null, { argv: false }).catch(() => {
// postcss-load-config throws error when no config file is found,
// but for us it's optional.
})
}
return loaded.then(config => {
var plugins = []
var options = {}
// inline postcss options for vue-loader
if (typeof inlineConfig === 'function') {
inlineConfig = inlineConfig.call(this, this)
}
if (Array.isArray(inlineConfig)) {
plugins = inlineConfig
} else if (isObject(inlineConfig)) {
plugins = inlineConfig.plugins || []
options = inlineConfig.options || {}
}
// merge postcss config file
if (config && config.plugins) {
plugins = plugins.concat(config.plugins)
}
if (config && config.options) {
options = Object.assign({}, config.options, options)
}
return {
plugins,
options
}
})
}