@@ -132,6 +132,7 @@ class SourceMapDevToolPlugin {
132
132
if ( currentSourceMappingURLComment !== false && / \. c s s ( $ | \? ) / i. test ( file ) ) {
133
133
currentSourceMappingURLComment = currentSourceMappingURLComment . replace ( / ^ \n \/ \/ ( .* ) $ / , "\n/*$1*/" ) ;
134
134
}
135
+ const sourceMapString = JSON . stringify ( sourceMap ) ;
135
136
if ( sourceMapFilename ) {
136
137
let filename = file ;
137
138
let query = "" ;
@@ -140,25 +141,25 @@ class SourceMapDevToolPlugin {
140
141
query = filename . substr ( idx ) ;
141
142
filename = filename . substr ( 0 , idx ) ;
142
143
}
143
- const sourceMapFile = compilation . getPath ( sourceMapFilename , {
144
+ let sourceMapFile = compilation . getPath ( sourceMapFilename , {
144
145
chunk,
145
146
filename,
146
147
query,
147
148
basename : basename ( filename )
148
149
} ) ;
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" ) ) ;
152
152
}
153
+ const sourceMapUrl = path . relative ( path . dirname ( file ) , sourceMapFile ) . replace ( / \\ / g, "/" ) ;
153
154
if ( currentSourceMappingURLComment !== false ) {
154
155
asset . __SourceMapDevToolData [ file ] = compilation . assets [ file ] = new ConcatSource ( new RawSource ( source ) , currentSourceMappingURLComment . replace ( / \[ u r l \] / g, sourceMapUrl ) ) ;
155
156
}
156
- asset . __SourceMapDevToolData [ sourceMapFile ] = compilation . assets [ sourceMapFile ] = new RawSource ( JSON . stringify ( sourceMap ) ) ;
157
+ asset . __SourceMapDevToolData [ sourceMapFile ] = compilation . assets [ sourceMapFile ] = new RawSource ( sourceMapString ) ;
157
158
chunk . files . push ( sourceMapFile ) ;
158
159
} else {
159
160
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
162
163
) ;
163
164
}
164
165
} ) ;
0 commit comments