Skip to content

Commit 60356c2

Browse files
committed
only generate sourcemap if needed
1 parent 16004ce commit 60356c2

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ module.exports = function (content) {
135135
}
136136
}
137137

138-
var parts = parse(content, fileName)
138+
var parts = parse(content, fileName, this.sourceMap)
139139
var hasLocalStyles = false
140140
var output = 'var __vue_script__, __vue_template__\n'
141141

lib/parser.js

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ var deindent = require('de-indent')
77
var splitRE = /\r?\n/g
88
var emptyRE = /^\s*$/
99

10-
module.exports = function (content, filename) {
10+
module.exports = function (content, filename, needMap) {
1111

1212
var cacheKey = hash(filename + content)
1313
// source-map cache busting for hot-reloadded modules
@@ -32,6 +32,7 @@ module.exports = function (content, filename) {
3232
var src = getAttribute(node, 'src')
3333
var scoped = getAttribute(node, 'scoped') != null
3434
var warnings = null
35+
var map = null
3536

3637
if (!output[type]) {
3738
return
@@ -101,36 +102,37 @@ module.exports = function (content, filename) {
101102
result = deindent(content.slice(start, end))
102103
}
103104

104-
// generate source map
105-
var map = new SourceMapGenerator()
106-
map.setSourceContent(filenameWithHash, content)
107-
result.split(splitRE).forEach(function (line, index) {
108-
map.addMapping({
109-
source: filenameWithHash,
110-
original: {
111-
line: index + 1 + lineOffset,
112-
column: 0
113-
},
114-
generated: {
115-
line: index + 1,
116-
column: 0
117-
}
105+
if (needMap) {
106+
// generate source map
107+
map = new SourceMapGenerator()
108+
map.setSourceContent(filenameWithHash, content)
109+
result.split(splitRE).forEach(function (line, index) {
110+
map.addMapping({
111+
source: filenameWithHash,
112+
original: {
113+
line: index + 1 + lineOffset,
114+
column: 0
115+
},
116+
generated: {
117+
line: index + 1,
118+
column: 0
119+
}
120+
})
118121
})
119-
})
120-
121-
// workaround for Webpack eval-source-map bug
122-
// https://github.com/webpack/webpack/pull/1816
123-
// in case the script was piped through another loader
124-
// that doesn't pass down the source map properly.
125-
if (type === 'script' && !lang) {
126-
result += '\n/* generated by vue-loader */\n'
122+
// workaround for Webpack eval-source-map bug
123+
// https://github.com/webpack/webpack/pull/1816
124+
// in case the script was piped through another loader
125+
// that doesn't pass down the source map properly.
126+
if (type === 'script' && !lang) {
127+
result += '\n/* generated by vue-loader */\n'
128+
}
127129
}
128130

129131
output[type].push({
130132
lang: lang,
131133
scoped: scoped,
132134
content: result,
133-
map: map.toJSON(),
135+
map: map && map.toJSON(),
134136
warnings: warnings
135137
})
136138
})

lib/selector.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function (content) {
66
this.cacheable()
77
var query = loaderUtils.parseQuery(this.query)
88
var filename = path.basename(this.resourcePath)
9-
var parts = parse(content, filename)
9+
var parts = parse(content, filename, this.sourceMap)
1010
var part = parts[query.type][query.index]
1111
this.callback(null, part.content, part.map)
1212
}

0 commit comments

Comments
 (0)