Skip to content

Commit 361438a

Browse files
committed
enable css source mapping if devtool option is set
1 parent e6f67c6 commit 361438a

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

lib/loader.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ module.exports = function (content) {
3838
defaultLoaders.js = 'babel-loader'
3939
}
4040

41+
// enable css source map if needed
42+
if (this.sourceMap) {
43+
defaultLoaders.css = 'style-loader!css-loader?sourceMap'
44+
}
45+
4146
// check if there are custom loaders specified via
4247
// webpack config, otherwise use defaults
4348
var loaders = assign({}, defaultLoaders, options.loaders)
@@ -92,12 +97,12 @@ module.exports = function (content) {
9297
}
9398
return injectString + ensureBang(loader)
9499
} else {
95-
// unknown lang, assume a loader for it is used
100+
// unknown lang, infer the loader to be used
96101
switch (type) {
97102
case 'template':
98-
return 'vue-html!' + rewriter + 'template-html?raw&engine=' + lang + '!'
103+
return defaultLoaders.html + '!' + rewriter + 'template-html-loader?raw&engine=' + lang + '!'
99104
case 'style':
100-
return 'style!css!' + rewriter + lang + '!'
105+
return defaultLoaders.css + '!' + rewriter + lang + '!'
101106
case 'script':
102107
return injectString + lang + '!'
103108
}

lib/style-rewriter.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,25 @@ module.exports = function (css, map) {
6767
opts = {
6868
from: file,
6969
to: file,
70-
map: {
70+
map: this.sourceMap && {
7171
inline: false,
7272
annotation: false
7373
}
7474
}
75-
if (map) {
75+
if (map && opts.map) {
7676
opts.map.prev = map
7777
}
7878

7979
currentId = query.id
8080
postcss(plugins)
8181
.process(css, opts)
8282
.then(function (result) {
83-
var map = result.map.toJSON()
83+
var map = result.map && result.map.toJSON()
8484
// ensure we give the style source a unique name
8585
// so that Webpack doesn't get confused
86-
map.sources[0] = query.file + '.style'
86+
if (map) {
87+
map.sources[0] = query.file + '.style'
88+
}
8789
cb(null, result.css, map)
8890
})
8991
.catch(function (e) {

test/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ describe('vue-loader', function () {
153153
var line
154154
var col
155155
var lines = code.split(/\r?\n/g)
156+
var targetRE = /^\s+msg: 'Hello from Component A!'/
156157
lines.some(function (l, i) {
157-
if (l.indexOf('Hello from Component A') > -1) {
158+
if (targetRE.test(l)) {
158159
line = i
159160
col = lines[i - 1].length
160161
return true

0 commit comments

Comments
 (0)