Skip to content

Commit c48e6fe

Browse files
Elevistayyx990803
authored andcommitted
fix #943, should consider path or file name includes dot (#945)
* keep path of source file in source map * fix #943, regex should consider path or file name includes dot * use path.extname rather than regex * add sourceRoot option for SourceMapGenerator
1 parent 597d26b commit c48e6fe

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

lib/parser.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ var SourceMapGenerator = require('source-map').SourceMapGenerator
66
var splitRE = /\r?\n/g
77
var emptyRE = /^(?:\/\/)?\s*$/
88

9-
module.exports = function (content, filename, needMap) {
9+
module.exports = function (content, filename, needMap, sourceRoot) {
1010
var cacheKey = hash(filename + content)
1111
// source-map cache busting for hot-reloadded modules
1212
var filenameWithHash = filename + '?' + cacheKey
@@ -18,7 +18,8 @@ module.exports = function (content, filename, needMap) {
1818
output.script.map = generateSourceMap(
1919
filenameWithHash,
2020
content,
21-
output.script.content
21+
output.script.content,
22+
sourceRoot
2223
)
2324
}
2425
if (output.styles) {
@@ -27,7 +28,8 @@ module.exports = function (content, filename, needMap) {
2728
style.map = generateSourceMap(
2829
filenameWithHash,
2930
content,
30-
style.content
31+
style.content,
32+
sourceRoot
3133
)
3234
}
3335
})
@@ -37,8 +39,8 @@ module.exports = function (content, filename, needMap) {
3739
return output
3840
}
3941

40-
function generateSourceMap (filename, source, generated) {
41-
var map = new SourceMapGenerator()
42+
function generateSourceMap (filename, source, generated, sourceRoot) {
43+
var map = new SourceMapGenerator({ sourceRoot })
4244
map.setSourceContent(filename, source)
4345
generated.split(splitRE).forEach((line, index) => {
4446
if (!emptyRE.test(line)) {

lib/selector.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ module.exports = function (content) {
1010
this.cacheable()
1111
var query = loaderUtils.getOptions(this) || {}
1212
var context = (this._compiler && this._compiler.context) || this.options.context || process.cwd()
13-
var filename = path.relative(context, this.resourcePath).replace(/\..+$/, '.vue')
14-
var parts = parse(content, filename, this.sourceMap)
13+
var filename = path.basename(this.resourcePath)
14+
filename = filename.substring(0, filename.lastIndexOf(path.extname(filename))) + '.vue'
15+
var sourceRoot = path.dirname(path.relative(context, this.resourcePath))
16+
var parts = parse(content, filename, this.sourceMap, sourceRoot)
1517
var part = parts[query.type]
1618
if (Array.isArray(part)) {
1719
part = part[query.index]

0 commit comments

Comments
 (0)