@@ -132,6 +132,7 @@ class SourceMapDevToolPlugin {
132132 if ( currentSourceMappingURLComment !== false && / \. c s s ( $ | \? ) / i. test ( file ) ) {
133133 currentSourceMappingURLComment = currentSourceMappingURLComment . replace ( / ^ \n \/ \/ ( .* ) $ / , "\n/*$1*/" ) ;
134134 }
135+ const sourceMapString = JSON . stringify ( sourceMap ) ;
135136 if ( sourceMapFilename ) {
136137 let filename = file ;
137138 let query = "" ;
@@ -140,25 +141,25 @@ class SourceMapDevToolPlugin {
140141 query = filename . substr ( idx ) ;
141142 filename = filename . substr ( 0 , idx ) ;
142143 }
143- const sourceMapFile = compilation . getPath ( sourceMapFilename , {
144+ let sourceMapFile = compilation . getPath ( sourceMapFilename , {
144145 chunk,
145146 filename,
146147 query,
147148 basename : basename ( filename )
148149 } ) ;
149- let sourceMapUrl = path . relative ( path . dirname ( file ) , sourceMapFile ) . replace ( / \\ / g, "/" ) ;
150- if ( sourceMapUrl . indexOf ( "[contenthash]" ) !== - 1 ) {
151- sourceMapUrl = sourceMapUrl . replace ( / \[ c o n t e n t h a s h \] / g, crypto . createHash ( "md5" ) . update ( source ) . digest ( "hex" ) ) ;
150+ if ( sourceMapFile . indexOf ( "[contenthash]" ) !== - 1 ) {
151+ sourceMapFile = sourceMapFile . replace ( / \[ c o n t e n t h a s h \] / g, crypto . createHash ( "md5" ) . update ( sourceMapString ) . digest ( "hex" ) ) ;
152152 }
153+ const sourceMapUrl = path . relative ( path . dirname ( file ) , sourceMapFile ) . replace ( / \\ / g, "/" ) ;
153154 if ( currentSourceMappingURLComment !== false ) {
154155 asset . __SourceMapDevToolData [ file ] = compilation . assets [ file ] = new ConcatSource ( new RawSource ( source ) , currentSourceMappingURLComment . replace ( / \[ u r l \] / g, sourceMapUrl ) ) ;
155156 }
156- asset . __SourceMapDevToolData [ sourceMapFile ] = compilation . assets [ sourceMapFile ] = new RawSource ( JSON . stringify ( sourceMap ) ) ;
157+ asset . __SourceMapDevToolData [ sourceMapFile ] = compilation . assets [ sourceMapFile ] = new RawSource ( sourceMapString ) ;
157158 chunk . files . push ( sourceMapFile ) ;
158159 } else {
159160 asset . __SourceMapDevToolData [ file ] = compilation . assets [ file ] = new ConcatSource ( new RawSource ( source ) , currentSourceMappingURLComment
160- . replace ( / \[ m a p \] / g, ( ) => JSON . stringify ( sourceMap ) )
161- . replace ( / \[ u r l \] / g, ( ) => `data:application/json;charset=utf-8;base64,${ new Buffer ( JSON . stringify ( sourceMap ) , "utf-8" ) . toString ( "base64" ) } ` ) // eslint-disable-line
161+ . replace ( / \[ m a p \] / g, ( ) => sourceMapString )
162+ . replace ( / \[ u r l \] / g, ( ) => `data:application/json;charset=utf-8;base64,${ new Buffer ( sourceMapString , "utf-8" ) . toString ( "base64" ) } ` ) // eslint-disable-line
162163 ) ;
163164 }
164165 } ) ;
0 commit comments