@@ -7,7 +7,7 @@ var deindent = require('de-indent')
77var splitRE = / \r ? \n / g
88var 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 } )
0 commit comments