Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: minify css only when needed #5178

Merged
merged 4 commits into from Oct 23, 2021
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -308,17 +308,19 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {

// build CSS handling ----------------------------------------------------

const used = usedRE.test(id)

// record css
if (!inlined) {
styles.set(id, css)
} else {
} else if (!modulesCode && used) {
css = await minifyCSS(css, config)
}

return {
code:
modulesCode ||
(usedRE.test(id)
(used
? `export default ${JSON.stringify(css)}`
: `export default ''`),
map: { mappings: '' },
Expand Down