Skip to content

Commit

Permalink
feat: supported cascading postcss config (#1147)
Browse files Browse the repository at this point in the history
close #1063
  • Loading branch information
Jinjiang authored and yyx990803 committed Mar 6, 2018
1 parent 2c8d1fb commit dddd911
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/style-compiler/load-postcss-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
})
}

if (process.env.VUE_LOADER_TEST || !loaded) {
if (process.env.VUE_LOADER_TEST || inlineConfig.cascade || !loaded) {
const config = inlineConfig.config || {}
const ctx = { webpack: loaderContext }
if (config.ctx) {
ctx.options = config.ctx
}
loaded = load(ctx, config.path, { argv: false }).catch(err => {
const configPath = (inlineConfig.cascade && !config.path)
? loaderContext.resourcePath
: config.path
loaded = load(ctx, configPath, { argv: false }).catch(err => {
// postcss-load-config throws error when no config file is found,
// but for us it's optional. only emit other errors
if (err.message.indexOf('No PostCSS Config found') >= 0) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"vue-template-compiler": "^2.0.0"
},
"devDependencies": {
"autoprefixer": "^7.2.5",
"babel-core": "^6.25.0",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.6.0",
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/sub/.postcssrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
plugins: {
autoprefixer: {}
}
}
3 changes: 3 additions & 0 deletions test/fixtures/sub/postcss-cascade.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<style>
body { display: flex }
</style>
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,20 @@ describe('vue-loader', () => {
})
})

it('load cascading postcss config file', done => {
fs.writeFileSync('.postcssrc', JSON.stringify({ parser: 'sugarss' }))
test({
entry: 'sub/postcss-cascade.vue',
vue: { postcss: { cascade: true }}
}, (window) => {
let style = window.document.querySelector('style').textContent
style = normalizeNewline(style)
expect(style).to.contain('display: -webkit-box')
fs.unlinkSync('.postcssrc')
done()
})
})

it('load postcss config file by path', done => {
fs.writeFileSync('test/.postcssrc', JSON.stringify({ parser: 'sugarss' }))
test({
Expand Down

0 comments on commit dddd911

Please sign in to comment.