@@ -469,7 +469,7 @@ function readThrough (
469469 debug ( 'readThrough' , fileName )
470470
471471 const [ value , sourceMap ] = compile ( code , fileName , lineOffset )
472- const output = updateOutput ( value , fileName , sourceMap )
472+ const output = updateOutput ( value , fileName , sourceMap , getExtension )
473473
474474 cache . outputs [ fileName ] = output
475475
@@ -494,7 +494,7 @@ function readThrough (
494494 } catch ( err ) { /* Ignore. */ }
495495
496496 const [ value , sourceMap ] = compile ( code , fileName , lineOffset )
497- const output = updateOutput ( value , fileName , sourceMap )
497+ const output = updateOutput ( value , fileName , sourceMap , getExtension )
498498
499499 cache . outputs [ fileName ] = output
500500 writeFileSync ( outputPath , output )
@@ -506,11 +506,12 @@ function readThrough (
506506/**
507507 * Update the output remapping the source map.
508508 */
509- function updateOutput ( outputText : string , fileName : string , sourceMap : string ) {
509+ function updateOutput ( outputText : string , fileName : string , sourceMap : string , getExtension : ( fileName : string ) => string ) {
510510 const base64Map = new Buffer ( updateSourceMap ( sourceMap , fileName ) , 'utf8' ) . toString ( 'base64' )
511511 const sourceMapContent = `data:application/json;charset=utf-8;base64,${ base64Map } `
512+ const sourceMapLength = `${ basename ( fileName ) } .map` . length + ( getExtension ( fileName ) . length - extname ( fileName ) . length )
512513
513- return outputText . replace ( / [ ^ = ] + $ / , sourceMapContent )
514+ return outputText . slice ( 0 , - 1 * sourceMapLength ) + sourceMapContent
514515}
515516
516517/**
0 commit comments