Skip to content

Commit

Permalink
feat(css): add css.minify option to Vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson committed Jan 1, 2022
1 parent 0db0536 commit dbc1020
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { transform, formatMessages } from 'esbuild'
// const debug = createDebugger('vite:css')

export interface CSSOptions {
minify?: boolean
/**
* https://github.com/css-modules/postcss-modules
*/
Expand Down Expand Up @@ -249,6 +250,8 @@ export function cssPlugin(config: ResolvedConfig): Plugin {
*/
export function cssPostPlugin(config: ResolvedConfig): Plugin {
const { chunkToEmittedCssFileMap } = config
const isMinificationEnabled =
config.build.minify !== false || config.css?.minify === true

// styles initialization in buildStart causes a styling loss in watch
const styles: Map<string, string> = new Map<string, string>()
Expand Down Expand Up @@ -382,7 +385,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
if (css.includes('@import')) {
css = await hoistAtImports(css)
}
if (minify && config.build.minify) {
if (minify && isMinificationEnabled) {
css = await minifyCSS(css, config)
}
return css
Expand Down Expand Up @@ -498,7 +501,7 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
if (extractedCss && !hasEmitted) {
hasEmitted = true
// minify css
if (config.build.minify) {
if (isMinificationEnabled) {
extractedCss = await minifyCSS(extractedCss, config)
}
this.emitFile({
Expand Down

0 comments on commit dbc1020

Please sign in to comment.