Skip to content

Commit 7882234

Browse files
committed
properly support sourcemaps in style-rewriter
1 parent 12628f6 commit 7882234

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

lib/style-rewriter.js

+25-7
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,21 @@ var addId = postcss.plugin('add-id', function () {
3030
}
3131
})
3232

33-
module.exports = function (css) {
33+
module.exports = function (css, map) {
3434
this.cacheable()
3535
var cb = this.async()
3636

3737
var query = loaderUtils.parseQuery(this.query)
3838
var options = this.options.vue || {}
3939
var autoprefixOptions = options.autoprefixer
40+
var plugins = []
4041

41-
var processors = []
42+
// scoped css
4243
if (query.scoped) {
43-
processors.push(addId)
44+
plugins.push(addId)
4445
}
46+
47+
// autoprefixer
4548
if (autoprefixOptions !== false) {
4649
autoprefixOptions = assign(
4750
{},
@@ -50,14 +53,29 @@ module.exports = function (css) {
5053
autoprefixOptions
5154
)
5255
var autoprefixer = require('autoprefixer')(autoprefixOptions)
53-
processors.push(autoprefixer)
56+
plugins.push(autoprefixer)
57+
}
58+
59+
// postcss options, for source maps
60+
var file = loaderUtils.getRemainingRequest(this)
61+
var opts
62+
opts = {
63+
from: file,
64+
to: file,
65+
map: {
66+
inline: false,
67+
annotation: false
68+
}
69+
}
70+
if (map) {
71+
opts.map.prev = map
5472
}
5573

5674
currentId = '_v-' + hash(this.resourcePath)
57-
postcss(processors)
58-
.process(css)
75+
postcss(plugins)
76+
.process(css, opts)
5977
.then(function (result) {
60-
cb(null, result)
78+
cb(null, result.css, result.map)
6179
})
6280
.catch(function (e) {
6381
console.log(e)

0 commit comments

Comments
 (0)