diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 4dc3aa7f158587..aacd6cd0ccf732 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -380,7 +380,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { const cssContent = await getContentWithSourcemap(css) const devBase = config.base - return [ + const code = [ `import { updateStyle as __vite__updateStyle, removeStyle as __vite__removeStyle } from ${JSON.stringify( path.posix.join(devBase, CLIENT_PUBLIC_PATH) )}`, @@ -394,6 +394,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { }`, `import.meta.hot.prune(() => __vite__removeStyle(__vite__id))` ].join('\n') + return { code, map: { mappings: '' } } } // build CSS handling ---------------------------------------------------- diff --git a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts index cee31201cb2f6f..d7e9a5e8ecd71d 100644 --- a/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts +++ b/playground/css-sourcemap/__tests__/css-sourcemap.spec.ts @@ -90,6 +90,18 @@ describe.runIf(isServe)('serve', () => { `) }) + test.runIf(isServe)( + 'js .css request does not include sourcemap', + async () => { + const res = await page.request.get( + new URL('./linked-with-import.css', page.url()).href + ) + const content = await res.text() + const lines = content.trim().split('\n') + expect(lines[lines.length - 1]).not.toMatch(/^\/\/#/) + } + ) + test('imported css', async () => { const css = await getStyleTagContentIncluding('.imported ') const map = extractSourcemap(css)