Skip to content

Commit dddd911

Browse files
Jinjiangyyx990803
authored andcommitted
feat: supported cascading postcss config (#1147)
close #1063
1 parent 2c8d1fb commit dddd911

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
1414
})
1515
}
1616

17-
if (process.env.VUE_LOADER_TEST || !loaded) {
17+
if (process.env.VUE_LOADER_TEST || inlineConfig.cascade || !loaded) {
1818
const config = inlineConfig.config || {}
1919
const ctx = { webpack: loaderContext }
2020
if (config.ctx) {
2121
ctx.options = config.ctx
2222
}
23-
loaded = load(ctx, config.path, { argv: false }).catch(err => {
23+
const configPath = (inlineConfig.cascade && !config.path)
24+
? loaderContext.resourcePath
25+
: config.path
26+
loaded = load(ctx, configPath, { argv: false }).catch(err => {
2427
// postcss-load-config throws error when no config file is found,
2528
// but for us it's optional. only emit other errors
2629
if (err.message.indexOf('No PostCSS Config found') >= 0) {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"vue-template-compiler": "^2.0.0"
6262
},
6363
"devDependencies": {
64+
"autoprefixer": "^7.2.5",
6465
"babel-core": "^6.25.0",
6566
"babel-loader": "^7.0.0",
6667
"babel-preset-env": "^1.6.0",

test/fixtures/sub/.postcssrc.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
plugins: {
3+
autoprefixer: {}
4+
}
5+
}

test/fixtures/sub/postcss-cascade.vue

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<style>
2+
body { display: flex }
3+
</style>

test/test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,20 @@ describe('vue-loader', () => {
488488
})
489489
})
490490

491+
it('load cascading postcss config file', done => {
492+
fs.writeFileSync('.postcssrc', JSON.stringify({ parser: 'sugarss' }))
493+
test({
494+
entry: 'sub/postcss-cascade.vue',
495+
vue: { postcss: { cascade: true }}
496+
}, (window) => {
497+
let style = window.document.querySelector('style').textContent
498+
style = normalizeNewline(style)
499+
expect(style).to.contain('display: -webkit-box')
500+
fs.unlinkSync('.postcssrc')
501+
done()
502+
})
503+
})
504+
491505
it('load postcss config file by path', done => {
492506
fs.writeFileSync('test/.postcssrc', JSON.stringify({ parser: 'sugarss' }))
493507
test({

0 commit comments

Comments
 (0)