@@ -2054,69 +2054,70 @@ async function minifyCSS(
2054
2054
// regular CSS assets do end with a linebreak.
2055
2055
// See https://github.com/vitejs/vite/pull/13893#issuecomment-1678628198
2056
2056
2057
- if ( config . build . cssMinify === 'lightningcss ' ) {
2057
+ if ( config . build . cssMinify === 'esbuild ' ) {
2058
2058
try {
2059
- const { code, warnings } = ( await importLightningCSS ( ) ) . transform ( {
2060
- ...config . css . lightningcss ,
2061
- targets : convertTargets ( config . build . cssTarget ) ,
2062
- cssModules : undefined ,
2063
- // TODO: Pass actual filename here, which can also be passed to esbuild's
2064
- // `sourcefile` option below to improve error messages
2065
- filename : defaultCssBundleName ,
2066
- code : Buffer . from ( css ) ,
2067
- minify : true ,
2059
+ const { code, warnings } = await transform ( css , {
2060
+ loader : 'css' ,
2061
+ target : config . build . cssTarget || undefined ,
2062
+ ...resolveMinifyCssEsbuildOptions ( config . esbuild || { } ) ,
2068
2063
} )
2069
2064
if ( warnings . length ) {
2070
- const messages = warnings . map (
2071
- ( warning ) =>
2072
- `${ warning . message } \n` +
2073
- generateCodeFrame ( css , {
2074
- line : warning . loc . line ,
2075
- column : warning . loc . column - 1 , // 1-based
2076
- } ) ,
2077
- )
2065
+ const msgs = await formatMessages ( warnings , { kind : 'warning' } )
2078
2066
config . logger . warn (
2079
- colors . yellow ( `warnings when minifying css:\n${ messages . join ( '\n' ) } ` ) ,
2067
+ colors . yellow ( `warnings when minifying css:\n${ msgs . join ( '\n' ) } ` ) ,
2080
2068
)
2081
2069
}
2082
-
2083
- // NodeJS res.code = Buffer
2084
- // Deno res.code = Uint8Array
2085
- // For correct decode compiled css need to use TextDecoder
2086
- // LightningCSS output does not return a linebreak at the end
2087
- return decoder . decode ( code ) + ( inlined ? '' : '\n' )
2070
+ // esbuild output does return a linebreak at the end
2071
+ return inlined ? code . trimEnd ( ) : code
2088
2072
} catch ( e ) {
2089
- e . message = `[lightningcss minify] ${ e . message } `
2090
- if ( e . loc ) {
2091
- e . loc = {
2092
- line : e . loc . line ,
2093
- column : e . loc . column - 1 , // 1-based
2094
- }
2095
- e . frame = generateCodeFrame ( css , e . loc )
2073
+ if ( e . errors ) {
2074
+ e . message = '[esbuild css minify] ' + e . message
2075
+ const msgs = await formatMessages ( e . errors , { kind : 'error' } )
2076
+ e . frame = '\n' + msgs . join ( '\n' )
2077
+ e . loc = e . errors [ 0 ] . location
2096
2078
}
2097
2079
throw e
2098
2080
}
2099
2081
}
2082
+
2100
2083
try {
2101
- const { code, warnings } = await transform ( css , {
2102
- loader : 'css' ,
2103
- target : config . build . cssTarget || undefined ,
2104
- ...resolveMinifyCssEsbuildOptions ( config . esbuild || { } ) ,
2084
+ const { code, warnings } = ( await importLightningCSS ( ) ) . transform ( {
2085
+ ...config . css . lightningcss ,
2086
+ targets : convertTargets ( config . build . cssTarget ) ,
2087
+ cssModules : undefined ,
2088
+ // TODO: Pass actual filename here, which can also be passed to esbuild's
2089
+ // `sourcefile` option below to improve error messages
2090
+ filename : defaultCssBundleName ,
2091
+ code : Buffer . from ( css ) ,
2092
+ minify : true ,
2105
2093
} )
2106
2094
if ( warnings . length ) {
2107
- const msgs = await formatMessages ( warnings , { kind : 'warning' } )
2095
+ const messages = warnings . map (
2096
+ ( warning ) =>
2097
+ `${ warning . message } \n` +
2098
+ generateCodeFrame ( css , {
2099
+ line : warning . loc . line ,
2100
+ column : warning . loc . column - 1 , // 1-based
2101
+ } ) ,
2102
+ )
2108
2103
config . logger . warn (
2109
- colors . yellow ( `warnings when minifying css:\n${ msgs . join ( '\n' ) } ` ) ,
2104
+ colors . yellow ( `warnings when minifying css:\n${ messages . join ( '\n' ) } ` ) ,
2110
2105
)
2111
2106
}
2112
- // esbuild output does return a linebreak at the end
2113
- return inlined ? code . trimEnd ( ) : code
2107
+
2108
+ // NodeJS res.code = Buffer
2109
+ // Deno res.code = Uint8Array
2110
+ // For correct decode compiled css need to use TextDecoder
2111
+ // LightningCSS output does not return a linebreak at the end
2112
+ return decoder . decode ( code ) + ( inlined ? '' : '\n' )
2114
2113
} catch ( e ) {
2115
- if ( e . errors ) {
2116
- e . message = '[esbuild css minify] ' + e . message
2117
- const msgs = await formatMessages ( e . errors , { kind : 'error' } )
2118
- e . frame = '\n' + msgs . join ( '\n' )
2119
- e . loc = e . errors [ 0 ] . location
2114
+ e . message = `[lightningcss minify] ${ e . message } `
2115
+ if ( e . loc ) {
2116
+ e . loc = {
2117
+ line : e . loc . line ,
2118
+ column : e . loc . column - 1 , // 1-based
2119
+ }
2120
+ e . frame = generateCodeFrame ( css , e . loc )
2120
2121
}
2121
2122
throw e
2122
2123
}
0 commit comments