Skip to content

Supported cascading postcss config #1147

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -507,6 +507,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