From eccf663e35a17458425860895bb30b3b0613ea96 Mon Sep 17 00:00:00 2001 From: Bjorn Lu Date: Wed, 30 Oct 2024 16:14:44 +0800 Subject: [PATCH] fix(css)!: remove default import in ssr dev (#17922) Co-authored-by: patak <583075+patak-dev@users.noreply.github.com> --- packages/vite/src/node/plugins/css.ts | 7 +++---- .../src/node/ssr/runtime/__tests__/server-runtime.spec.ts | 7 +------ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 9fde18e8bca0cb..2373ecf6ea50a3 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -539,13 +539,12 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { if (isDirectCSSRequest(id)) { return null } - // server only - if (this.environment.config.consumer !== 'client') { - return modulesCode || `export default ${JSON.stringify(css)}` - } if (inlined) { return `export default ${JSON.stringify(css)}` } + if (this.environment.config.consumer === 'server') { + return modulesCode || 'export {}' + } const cssContent = await getContentWithSourcemap(css) const code = [ diff --git a/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts b/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts index 7c03610f73288e..4c47558c210517 100644 --- a/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts +++ b/packages/vite/src/node/ssr/runtime/__tests__/server-runtime.spec.ts @@ -32,12 +32,7 @@ describe('module runner initialization', async () => { it('css is loaded correctly', async ({ runner }) => { const css = await runner.import('/fixtures/test.css') - expect(css.default).toMatchInlineSnapshot(` - ".test { - color: red; - } - " - `) + expect(css.default).toBe(undefined) const module = await runner.import('/fixtures/test.module.css') expect(module).toMatchObject({ default: {