@@ -7,7 +7,7 @@ var deindent = require('de-indent')
7
7
var splitRE = / \r ? \n / g
8
8
var emptyRE = / ^ \s * $ /
9
9
10
- module . exports = function ( content , filename ) {
10
+ module . exports = function ( content , filename , needMap ) {
11
11
12
12
var cacheKey = hash ( filename + content )
13
13
// source-map cache busting for hot-reloadded modules
@@ -32,6 +32,7 @@ module.exports = function (content, filename) {
32
32
var src = getAttribute ( node , 'src' )
33
33
var scoped = getAttribute ( node , 'scoped' ) != null
34
34
var warnings = null
35
+ var map = null
35
36
36
37
if ( ! output [ type ] ) {
37
38
return
@@ -101,36 +102,37 @@ module.exports = function (content, filename) {
101
102
result = deindent ( content . slice ( start , end ) )
102
103
}
103
104
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
+ } )
118
121
} )
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
+ }
127
129
}
128
130
129
131
output [ type ] . push ( {
130
132
lang : lang ,
131
133
scoped : scoped ,
132
134
content : result ,
133
- map : map . toJSON ( ) ,
135
+ map : map && map . toJSON ( ) ,
134
136
warnings : warnings
135
137
} )
136
138
} )
0 commit comments