Skip to content

Commit

Permalink
fix(css): fix sass modern source map (#17938)
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa authored Sep 1, 2024
1 parent ad13760 commit d428e7e
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 10 deletions.
6 changes: 6 additions & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2438,6 +2438,12 @@ const scssProcessor = (
? JSON.parse(result.map.toString())
: undefined

if (map) {
map.sources = map.sources.map((url) =>
url.startsWith('file://') ? normalizePath(fileURLToPath(url)) : url,
)
}

return {
code: result.css.toString(),
map,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../css-sourcemap.spec'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import '../css-sourcemap.spec'
15 changes: 15 additions & 0 deletions playground/css-sourcemap/vite.config-sass-modern-compiler.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig, mergeConfig } from 'vite'
import baseConfig from './vite.config.js'

export default mergeConfig(
baseConfig,
defineConfig({
css: {
preprocessorOptions: {
sass: {
api: 'modern-compiler',
},
},
},
}),
)
15 changes: 15 additions & 0 deletions playground/css-sourcemap/vite.config-sass-modern.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { defineConfig, mergeConfig } from 'vite'
import baseConfig from './vite.config.js'

export default mergeConfig(
baseConfig,
defineConfig({
css: {
preprocessorOptions: {
sass: {
api: 'modern',
},
},
},
}),
)
22 changes: 12 additions & 10 deletions playground/vitestGlobalSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,18 @@ export async function setup({ provide }: GlobalSetupContext): Promise<void> {
}
})
// also setup dedicated copy for "variant" tests
await fs.cp(
path.resolve(tempDir, 'css'),
path.resolve(tempDir, 'css__sass-modern'),
{ recursive: true },
)
await fs.cp(
path.resolve(tempDir, 'css'),
path.resolve(tempDir, 'css__sass-modern-compiler'),
{ recursive: true },
)
for (const [original, variants] of [
['css', ['sass-modern', 'sass-modern-compiler']],
['css-sourcemap', ['sass-modern', 'sass-modern-compiler']],
] as const) {
for (const variant of variants) {
await fs.cp(
path.resolve(tempDir, original),
path.resolve(tempDir, `${original}__${variant}`),
{ recursive: true },
)
}
}
}

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

0 comments on commit d428e7e

Please sign in to comment.