@@ -9,21 +9,24 @@ interface InstallSourceMapSupportOptions {
99let SOURCEMAPPING_URL = 'sourceMa'
1010SOURCEMAPPING_URL += 'ppingURL'
1111
12- const VITE_NODE_SOURCEMAPPING_URL = `${ SOURCEMAPPING_URL } =data:application/json;charset=utf-8;source=vite-node`
12+ const VITE_NODE_SOURCEMAPPING_SOURCE = '//# sourceMappingSource=vite-node'
13+ const VITE_NODE_SOURCEMAPPING_URL = `${ SOURCEMAPPING_URL } =data:application/json;charset=utf-8`
1314const VITE_NODE_SOURCEMAPPING_REGEXP = new RegExp ( `//# ${ VITE_NODE_SOURCEMAPPING_URL } ;base64,(.+)` )
14- const OTHER_SOURCE_MAP_REGEXP = new RegExp ( `//# ${ SOURCEMAPPING_URL } =data:application/json[^,]+base64,(.+)` )
1515
1616export async function withInlineSourcemap ( result : TransformResult ) {
17- const { code, map } = result
17+ const map = result . map
18+ let code = result . code
1819
19- if ( ! map || code . includes ( VITE_NODE_SOURCEMAPPING_URL ) )
20+ if ( ! map || code . includes ( VITE_NODE_SOURCEMAPPING_SOURCE ) )
2021 return result
2122
2223 // to reduce the payload size, we only inline vite node source map, because it's also the only one we use
23- if ( OTHER_SOURCE_MAP_REGEXP . test ( code ) )
24- result . code = code . replace ( OTHER_SOURCE_MAP_REGEXP , '' )
24+ const OTHER_SOURCE_MAP_REGEXP = new RegExp ( `//# ${ SOURCEMAPPING_URL } =data:application/json[^,]+base64,(.+)` , 'g' )
25+ while ( OTHER_SOURCE_MAP_REGEXP . test ( code ) )
26+ code = code . replace ( OTHER_SOURCE_MAP_REGEXP , '' )
2527
26- result . code = `${ code } \n\n//# ${ VITE_NODE_SOURCEMAPPING_URL } ;base64,${ Buffer . from ( JSON . stringify ( map ) , 'utf-8' ) . toString ( 'base64' ) } \n`
28+ const sourceMap = Buffer . from ( JSON . stringify ( map ) , 'utf-8' ) . toString ( 'base64' )
29+ result . code = `${ code . trimEnd ( ) } \n\n${ VITE_NODE_SOURCEMAPPING_SOURCE } \n//# ${ VITE_NODE_SOURCEMAPPING_URL } ;base64,${ sourceMap } \n`
2730
2831 return result
2932}
0 commit comments