@@ -27,6 +27,8 @@ export interface SendOptions {
27
27
cacheControl ?: string
28
28
headers ?: OutgoingHttpHeaders
29
29
map ?: SourceMap | { mappings : '' } | null
30
+ /** only used when type === 'js' && map == null (when the fallback sourcemap is used) */
31
+ originalContent ?: string
30
32
}
31
33
32
34
export function send (
@@ -71,23 +73,25 @@ export function send(
71
73
}
72
74
// inject fallback sourcemap for js for improved debugging
73
75
// https://github.com/vitejs/vite/pull/13514#issuecomment-1592431496
74
- else if ( type === 'js' && ( ! map || map . mappings !== '' ) ) {
76
+ // for { mappings: "" }, we don't inject fallback sourcemap
77
+ // because it indicates generating a sourcemap is meaningless
78
+ else if ( type === 'js' && map == null ) {
75
79
const code = content . toString ( )
76
80
// if the code has existing inline sourcemap, assume it's correct and skip
77
81
if ( convertSourceMap . mapFileCommentRegex . test ( code ) ) {
78
82
debug ?.( `Skipped injecting fallback sourcemap for ${ req . url } ` )
79
83
} else {
80
84
const urlWithoutTimestamp = removeTimestampQuery ( req . url ! )
81
85
const ms = new MagicString ( code )
82
- content = getCodeWithSourcemap (
83
- type ,
84
- code ,
85
- ms . generateMap ( {
86
- source : path . basename ( urlWithoutTimestamp ) ,
87
- hires : 'boundary' ,
88
- includeContent : true ,
89
- } ) ,
90
- )
86
+ const map = ms . generateMap ( {
87
+ source : path . basename ( urlWithoutTimestamp ) ,
88
+ hires : 'boundary' ,
89
+ includeContent : ! options . originalContent ,
90
+ } )
91
+ if ( options . originalContent != null ) {
92
+ map . sourcesContent = [ options . originalContent ]
93
+ }
94
+ content = getCodeWithSourcemap ( type , code , map )
91
95
}
92
96
}
93
97
0 commit comments