From 7fddbb74b755a76e88f8e44f97f7c03df9afb6ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Sun, 10 Sep 2023 21:46:18 +0900 Subject: [PATCH] fix: use relative path for sources field (#14247) --- packages/vite/src/node/server/send.ts | 7 ++++++- playground/js-sourcemap/__tests__/js-sourcemap.spec.ts | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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, }