@@ -2054,69 +2054,70 @@ async function minifyCSS(
20542054 // regular CSS assets do end with a linebreak.
20552055 // See https://github.com/vitejs/vite/pull/13893#issuecomment-1678628198
20562056
2057- if ( config . build . cssMinify === 'lightningcss ' ) {
2057+ if ( config . build . cssMinify === 'esbuild ' ) {
20582058 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 || { } ) ,
20682063 } )
20692064 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' } )
20782066 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' ) } ` ) ,
20802068 )
20812069 }
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
20882072 } 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
20962078 }
20972079 throw e
20982080 }
20992081 }
2082+
21002083 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 ,
21052093 } )
21062094 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+ )
21082103 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' ) } ` ) ,
21102105 )
21112106 }
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' )
21142113 } 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 )
21202121 }
21212122 throw e
21222123 }
0 commit comments