Skip to content

Commit d428e7e

Browse files
authored
fix(css): fix sass modern source map (#17938)
1 parent ad13760 commit d428e7e

File tree

6 files changed

+50
-10
lines changed

6 files changed

+50
-10
lines changed

packages/vite/src/node/plugins/css.ts

+6
Original file line numberDiff line numberDiff line change
@@ -2438,6 +2438,12 @@ const scssProcessor = (
24382438
? JSON.parse(result.map.toString())
24392439
: undefined
24402440

2441+
if (map) {
2442+
map.sources = map.sources.map((url) =>
2443+
url.startsWith('file://') ? normalizePath(fileURLToPath(url)) : url,
2444+
)
2445+
}
2446+
24412447
return {
24422448
code: result.css.toString(),
24432449
map,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../css-sourcemap.spec'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '../css-sourcemap.spec'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig, mergeConfig } from 'vite'
2+
import baseConfig from './vite.config.js'
3+
4+
export default mergeConfig(
5+
baseConfig,
6+
defineConfig({
7+
css: {
8+
preprocessorOptions: {
9+
sass: {
10+
api: 'modern-compiler',
11+
},
12+
},
13+
},
14+
}),
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { defineConfig, mergeConfig } from 'vite'
2+
import baseConfig from './vite.config.js'
3+
4+
export default mergeConfig(
5+
baseConfig,
6+
defineConfig({
7+
css: {
8+
preprocessorOptions: {
9+
sass: {
10+
api: 'modern',
11+
},
12+
},
13+
},
14+
}),
15+
)

playground/vitestGlobalSetup.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,18 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
4242
}
4343
})
4444
// also setup dedicated copy for "variant" tests
45-
await fs.cp(
46-
path.resolve(tempDir, 'css'),
47-
path.resolve(tempDir, 'css__sass-modern'),
48-
{ recursive: true },
49-
)
50-
await fs.cp(
51-
path.resolve(tempDir, 'css'),
52-
path.resolve(tempDir, 'css__sass-modern-compiler'),
53-
{ recursive: true },
54-
)
45+
for (const [original, variants] of [
46+
['css', ['sass-modern', 'sass-modern-compiler']],
47+
['css-sourcemap', ['sass-modern', 'sass-modern-compiler']],
48+
] as const) {
49+
for (const variant of variants) {
50+
await fs.cp(
51+
path.resolve(tempDir, original),
52+
path.resolve(tempDir, `${original}__${variant}`),
53+
{ recursive: true },
54+
)
55+
}
56+
}
5557
}
5658

5759
export async function teardown(): Promise<void> {

0 commit comments

Comments
 (0)