diff --git a/packages/playground/css/__tests__/css.spec.ts b/packages/playground/css/__tests__/css.spec.ts index 6ca00e760349b1..9869bb34d2c690 100644 --- a/packages/playground/css/__tests__/css.spec.ts +++ b/packages/playground/css/__tests__/css.spec.ts @@ -15,7 +15,11 @@ import { // in later assertions to ensure CSS HMR doesn't reload the page test('imported css', async () => { const css = await page.textContent('.imported-css') - expect(css).toContain('.imported {') + expect(css).toMatch(/\.imported ?{/) + if (isBuild) { + expect(css.trim()).not.toContain('\n') // check minified + } + const glob = await page.textContent('.imported-css-glob') expect(glob).toContain('.dir-import') const globEager = await page.textContent('.imported-css-globEager') @@ -372,6 +376,10 @@ test('inlined-code', async () => { // should resolve assets expect(code).toContain('background:') expect(code).not.toContain('__VITE_ASSET__') + + if (isBuild) { + expect(code.trim()).not.toContain('\n') // check minified + } }) test('minify css', async () => { diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 42adafd4b8791d..9ead17822d23a9 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -376,7 +376,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin { code = modulesCode } else { let content = css - if (inlined) { + if (config.build.minify) { content = await minifyCSS(content, config) } code = `export default ${JSON.stringify(content)}`