Skip to content

Commit 9795614

Browse files
committed
optimize postcss config loading
1 parent 1d2e2b6 commit 9795614

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/load-postcss-config.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var load = require('postcss-load-config')
2+
3+
let postcssrc
4+
5+
module.exports = function loadPostcssConfig () {
6+
if (process.env.VUE_LOADER_TEST || !postcssrc) {
7+
return (postcssrc = load({}, null, { argv: false }).catch(() => {
8+
// postcss-load-config throws error when no config file is found,
9+
// but for us it's optional.
10+
}))
11+
} else {
12+
return postcssrc
13+
}
14+
}

lib/style-rewriter.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var postcss = require('postcss')
22
var loaderUtils = require('loader-utils')
3-
var loadPostcssConfig = require('postcss-load-config')
43
var selectorParser = require('postcss-selector-parser')
4+
var loadPostcssConfig = require('./load-postcss-config')
55

66
var addId = postcss.plugin('add-id', function (opts) {
77
return function (root) {
@@ -59,10 +59,7 @@ module.exports = function (css, map) {
5959
}
6060

6161
// use the same config loading interface as postcss-loader
62-
loadPostcssConfig({ webpack: this }, null, { argv: false }).catch(() => {
63-
// postcss-load-config throws error when no config file is found,
64-
// but for us it's optional.
65-
}).then(config => {
62+
loadPostcssConfig().then(config => {
6663
var plugins
6764
var options
6865

0 commit comments

Comments
 (0)