Skip to content

Commit 66d2051

Browse files
committed
fix style-rewriter bug and add test case
1 parent 674c3bc commit 66d2051

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

lib/style-rewriter.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ module.exports = function (css, map) {
3535
var query = loaderUtils.parseQuery(this.query)
3636
var options = this.options.vue || {}
3737
var autoprefixOptions = options.autoprefixer
38+
var postcssOptions = options.postcss
3839

39-
// plugins
40-
var plugins = options.postcss
41-
if (typeof plugins === 'function') {
42-
plugins = plugins.call(this, this)
43-
} else if (typeof options.postcss === 'object' && options.postcss.plugins) {
44-
plugins = options.postcss.plugins
40+
// postcss plugins
41+
var plugins
42+
if (Array.isArray(postcssOptions)) {
43+
plugins = postcssOptions
44+
} else if (typeof postcssOptions === 'function') {
45+
plugins = postcssOptions.call(this, this)
46+
} else if (isObject(postcssOptions) && postcssOptions.plugins) {
47+
plugins = postcssOptions.plugins
4548
}
4649
plugins = plugins ? plugins.slice() : [] // make sure to copy it
4750

@@ -75,7 +78,7 @@ module.exports = function (css, map) {
7578
!this.minimize &&
7679
options.cssSourceMap !== false &&
7780
process.env.NODE_ENV !== 'production' &&
78-
!options.postcss.options.map
81+
!(isObject(postcssOptions) && postcssOptions.options && postcssOptions.map)
7982
) {
8083
opts.map = {
8184
inline: false,
@@ -85,10 +88,10 @@ module.exports = function (css, map) {
8588
}
8689

8790
// postcss options from configuration
88-
if (options.postcss && options.postcss.options) {
89-
for (var option in options.postcss.options) {
91+
if (isObject(postcssOptions) && postcssOptions.options) {
92+
for (var option in postcssOptions.options) {
9093
if (!opts.hasOwnProperty(option)) {
91-
opts[option] = options.postcss.options[option]
94+
opts[option] = postcssOptions.options[option]
9295
}
9396
}
9497
}
@@ -104,3 +107,7 @@ module.exports = function (css, map) {
104107
cb(e)
105108
})
106109
}
110+
111+
function isObject (val) {
112+
return val && typeof val === 'object'
113+
}

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@
7474
"mkdirp": "^0.5.1",
7575
"mocha": "^2.2.5",
7676
"node-libs-browser": "^1.0.0",
77+
"postcss": "^5.0.21",
7778
"rimraf": "^2.4.0",
7879
"stylus": "^0.54.5",
7980
"stylus-loader": "^2.0.0",
81+
"sugarss": "^0.1.3",
8082
"vue-hot-reload-api": "^1.2.0",
8183
"vue-html-loader": "^1.0.0",
8284
"vue-style-loader": "^1.0.0",

test/fixtures/postcss.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<style>
2+
h1
3+
color: red
4+
font-size: 14px
5+
</style>

test/test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,21 @@ describe('vue-loader', function () {
259259
done()
260260
})
261261
})
262+
263+
it('postcss options', function (done) {
264+
test({
265+
entry: './test/fixtures/postcss.vue',
266+
vue: {
267+
postcss: {
268+
options: {
269+
parser: require('sugarss')
270+
}
271+
}
272+
}
273+
}, function (window) {
274+
var style = window.document.querySelector('style').textContent
275+
expect(style).to.contain('h1 {\n color: red;\n font-size: 14px\n}')
276+
done()
277+
})
278+
})
262279
})

0 commit comments

Comments
 (0)