diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 1f98267c3059d3..d1a3978a42f3cb 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -2267,7 +2267,7 @@ const makeModernScssWorker = ( fileURLToPath(canonicalUrl), options.filename, ) - return { contents, syntax } + return { contents, syntax, sourceMapUrl: canonicalUrl } }, } sassOptions.importers = [ @@ -2353,7 +2353,7 @@ const makeModernCompilerScssWorker = ( ) const contents = result.contents ?? (await fsp.readFile(result.file, 'utf-8')) - return { contents, syntax } + return { contents, syntax, sourceMapUrl: canonicalUrl } }, } sassOptions.importers = [ diff --git a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts index 6c6472c848823d..c60836f30f44ed 100644 --- a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts +++ b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts @@ -139,14 +139,19 @@ describe.runIf(isServe)('serve', () => { expect(formatSourcemapForSnapshot(map)).toMatchInlineSnapshot(` { "ignoreList": [], - "mappings": "AACE;EACE", + "mappings": "AAGE;EACE,UCJM", "sources": [ "/root/imported.sass", + "/root/imported-nested.sass", ], "sourcesContent": [ - ".imported + "@import "/imported-nested.sass" + + .imported &-sass - color: red + color: $primary + ", + "$primary: red ", ], "version": 3, diff --git a/playground/css-sourcemap/imported-nested.sass b/playground/css-sourcemap/imported-nested.sass new file mode 100644 index 00000000000000..b5f10d672c1cc5 --- /dev/null +++ b/playground/css-sourcemap/imported-nested.sass @@ -0,0 +1 @@ +$primary: red diff --git a/playground/css-sourcemap/imported.sass b/playground/css-sourcemap/imported.sass index 06fa634d5dd4e9..6392f94655abc3 100644 --- a/playground/css-sourcemap/imported.sass +++ b/playground/css-sourcemap/imported.sass @@ -1,3 +1,5 @@ +@import "/imported-nested.sass" + .imported &-sass - color: red + color: $primary