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 3 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
10 changes: 5 additions & 5 deletions packages/vite/src/node/plugins/css.ts
Expand Up @@ -55,8 +55,8 @@ export interface CSSOptions {
postcss?:
| string
| (Postcss.ProcessOptions & {
plugins?: Postcss.Plugin[]
})
plugins?: Postcss.Plugin[]
})
patak-dev marked this conversation as resolved.
Show resolved Hide resolved
}

export interface CSSModulesOptions {
Expand Down Expand Up @@ -311,15 +311,15 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
// record css
if (!inlined) {
styles.set(id, css)
} else {
css = await minifyCSS(css, config)
}

return {
code:
modulesCode ||
(usedRE.test(id)
? `export default ${JSON.stringify(css)}`
? `export default ${JSON.stringify(
inlined ? await minifyCSS(css, config) : css
)}`
: `export default ''`),
map: { mappings: '' },
// avoid the css module from being tree-shaken so that we can retrieve
Expand Down