From 7d47fc1c749053095a3345ca1d47406a5f31792a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 24 Sep 2024 13:11:46 +0900 Subject: [PATCH] fix(css): backport #18113, fix missing source file warning with sass modern api custom importer (#18183) Co-authored-by: Hiroshi Ogawa --- packages/vite/src/node/plugins/css.ts | 4 ++-- .../css-sourcemap/__tests__/css-sourcemap.spec.ts | 11 ++++++++--- playground/css-sourcemap/imported-nested.sass | 1 + playground/css-sourcemap/imported.sass | 4 +++- 4 files changed, 14 insertions(+), 6 deletions(-) create mode 100644 playground/css-sourcemap/imported-nested.sass 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