Skip to content

Commit

Permalink
fix(css): minify imported css code
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Apr 19, 2022
1 parent 5b6a950 commit e850783
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion packages/playground/css/__tests__/css.spec.ts
Expand Up @@ -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')
Expand Down Expand Up @@ -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 () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Expand Up @@ -370,7 +370,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)}`
Expand Down

0 comments on commit e850783

Please sign in to comment.