diff --git a/packages/vite/src/node/server/send.ts b/packages/vite/src/node/server/send.ts index 36f70049c47e88..564ab54d8de85f 100644 --- a/packages/vite/src/node/server/send.ts +++ b/packages/vite/src/node/server/send.ts @@ -3,6 +3,7 @@ import type { OutgoingHttpHeaders, ServerResponse, } from 'node:http' +import path from 'node:path' import getEtag from 'etag' import type { SourceMap } from 'rollup' import MagicString from 'magic-string' @@ -69,7 +70,11 @@ export function send( content = getCodeWithSourcemap( type, content.toString(), - ms.generateMap({ source: urlWithoutTimestamp, hires: 'boundary' }), + ms.generateMap({ + source: path.basename(urlWithoutTimestamp), + hires: 'boundary', + includeContent: true, + }), ) } } diff --git a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts index 8d1c9d46bc551d..06d073fe5b1e9e 100644 --- a/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts +++ b/playground/js-sourcemap/__tests__/js-sourcemap.spec.ts @@ -18,7 +18,11 @@ if (!isBuild) { { "mappings": "AAAA,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;", "sources": [ - "/foo.js", + "foo.js", + ], + "sourcesContent": [ + "export const foo = 'foo' + ", ], "version": 3, }