Skip to content

Commit 5f4bb65

Browse files
committed
improve CSS source map handling
1 parent 80886c3 commit 5f4bb65

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/loader.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var assign = require('object-assign')
33
var selectorPath = require.resolve('./selector')
44
var parserPath = require.resolve('./parser')
55
var hash = require('hash-sum')
6+
var path = require('path')
67

78
var defaultLang = {
89
template: 'html',
@@ -29,7 +30,9 @@ module.exports = function (content) {
2930
var output = ''
3031
var options = this.options.vue || {}
3132
var vueUrl = loaderUtils.getRemainingRequest(this)
32-
var moduleId = '_v-' + hash(this.resourcePath)
33+
var filePath = this.resourcePath
34+
var fileName = path.basename(filePath)
35+
var moduleId = '_v-' + hash(filePath)
3336

3437
// respect user babel options
3538
if (this.options.babel) {
@@ -102,11 +105,12 @@ module.exports = function (content) {
102105
}
103106

104107
function getRewriter (type, scoped) {
108+
var meta = '?id=' + moduleId + '&file=' + fileName
105109
switch (type) {
106110
case 'template':
107-
return scoped ? (rewriters.template + '?id=' + moduleId + '!') : ''
111+
return scoped ? (rewriters.template + meta + '!') : ''
108112
case 'style':
109-
return rewriters.style + '?id=' + moduleId + (scoped ? '&scoped=true!' : '!')
113+
return rewriters.style + meta + (scoped ? '&scoped=true!' : '!')
110114
default:
111115
return ''
112116
}

lib/style-rewriter.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = function (css, map) {
5656
}
5757

5858
// postcss options, for source maps
59-
var file = loaderUtils.getRemainingRequest(this)
59+
var file = this.resourcePath
6060
var opts
6161
opts = {
6262
from: file,
@@ -74,7 +74,11 @@ module.exports = function (css, map) {
7474
postcss(plugins)
7575
.process(css, opts)
7676
.then(function (result) {
77-
cb(null, result.css, result.map)
77+
var map = JSON.parse(result.map.toString())
78+
// ensure we give the style source a unique name
79+
// so that Webpack doesn't get confused
80+
map.sources[0] = query.file + '.style'
81+
cb(null, result.css, map)
7882
})
7983
.catch(function (e) {
8084
console.log(e)

0 commit comments

Comments
 (0)