From c9521e7d03156178f9d10a453c3825c0e0a713e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Tue, 30 Aug 2022 23:16:06 +0900 Subject: [PATCH] fix(css): remove css-post plugin sourcemap (#9914) --- packages/vite/src/node/plugins/css.ts | 3 ++- .../css-sourcemap/__tests__/css-sourcemap.spec.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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)