Skip to content

Commit 37de90a

Browse files
committed
align postcss config API with postcss-loader
1 parent 19c5414 commit 37de90a

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

docs/LANGS.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
11
* [English](en/)
2-
* [한국어](kr/)
3-
* [Русский](ru/)
4-
* [Português](pt_BR/)
5-
* [日本語](ja/)
6-
* [中文](zh-cn/)

docs/en/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- [preLoaders](options.md#preloaders)
2424
- [postLoaders](options.md#postloaders)
2525
- [postcss](options.md#postcss)
26+
- [postcss.config](options.md#postcssconfig)
2627
- [cssSourceMap](options.md#csssourcemap)
2728
- [esModule](options.md#esmodule)
2829
- [preserveWhitespace](options.md#preservewhitespace)
@@ -32,3 +33,4 @@
3233
- [buble](options.md#buble)
3334
- [extractCSS](options.md#extractcss)
3435
- [optimizeSSR](options.md#optimizessr)
36+
- [cacheBusting](options.md#cachebusting)

docs/en/options.md

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,30 @@ module.exports = {
112112
}
113113
```
114114

115-
### postcss.configRoot
115+
### postcss.config
116116

117-
> New in 13.2.0
117+
> New in 13.2.1
118118
119-
- type: `string`
120-
- default: `process.cwd()`
119+
- type: `Object`
120+
- default: `undefined`
121121

122-
Specify an alternative root directory for [postcss-load-config](https://github.com/michael-ciniawsky/postcss-load-config) to search for PostCSS config files in.
122+
This field allows customizing PostCSS config in the same way as [postcss-loader](https://github.com/postcss/postcss-loader#config-1).
123123

124-
``` js
125-
postcss: {
126-
configRoot: path.resolve('./src')
127-
}
128-
```
124+
- **postcss.config.path**
125+
126+
Specify a path (file or directory) to load the PostCSS config file from.
127+
128+
``` js
129+
postcss: {
130+
config: {
131+
path: path.resolve('./src')
132+
}
133+
}
134+
```
135+
136+
- **postcss.config.ctx**
137+
138+
Provide context to PostCSS plugins. See [postcss-loader docs](https://github.com/postcss/postcss-loader#context-ctx) for more details.
129139

130140
### cssSourceMap
131141

lib/style-compiler/load-postcss-config.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ function isObject (val) {
66
return val && typeof val === 'object'
77
}
88

9-
module.exports = function loadPostcssConfig (loaderContext, inlineConfig) {
9+
module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
1010
if (process.env.VUE_LOADER_TEST || !loaded) {
11-
loaded = load(
12-
{ webpack: loaderContext },
13-
isObject(inlineConfig) && inlineConfig.configRoot,
14-
{ argv: false }
15-
).catch(() => {
11+
const config = inlineConfig.config || {}
12+
const ctx = { webpack: loaderContext }
13+
if (config.ctx) {
14+
ctx.options = config.ctx
15+
}
16+
loaded = load(ctx, config.path, { argv: false }).catch(err => {
1617
// postcss-load-config throws error when no config file is found,
17-
// but for us it's optional.
18+
// but for us it's optional. only emit other errors
19+
if (err.message.indexOf('No PostCSS Config found') < 0) {
20+
loaderContext.emitError(err)
21+
}
1822
})
1923
}
2024

test/test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ describe('vue-loader', function () {
487487
entry: './test/fixtures/postcss.vue',
488488
vue: {
489489
postcss: {
490-
configRoot: path.resolve('test')
490+
config: {
491+
path: path.resolve('test')
492+
}
491493
}
492494
}
493495
}, (window) => {

0 commit comments

Comments
 (0)