@@ -9,21 +9,24 @@ interface InstallSourceMapSupportOptions {
9
9
let SOURCEMAPPING_URL = 'sourceMa'
10
10
SOURCEMAPPING_URL += 'ppingURL'
11
11
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`
13
14
const 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,(.+)` )
15
15
16
16
export async function withInlineSourcemap ( result : TransformResult ) {
17
- const { code, map } = result
17
+ const map = result . map
18
+ let code = result . code
18
19
19
- if ( ! map || code . includes ( VITE_NODE_SOURCEMAPPING_URL ) )
20
+ if ( ! map || code . includes ( VITE_NODE_SOURCEMAPPING_SOURCE ) )
20
21
return result
21
22
22
23
// 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 , '' )
25
27
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`
27
30
28
31
return result
29
32
}
0 commit comments