@@ -1480,7 +1480,7 @@ async function compileCSS(
14801480 }
14811481 } else if ( message . type === 'warning' ) {
14821482 const warning = message as PostCSS . Warning
1483- let msg = `[vite:css] ${ warning . text } `
1483+ let msg = `[vite:css][postcss] ${ warning . text } `
14841484 msg += `\n${ generateCodeFrame (
14851485 code ,
14861486 {
@@ -1922,31 +1922,47 @@ async function minifyCSS(
19221922 // See https://github.com/vitejs/vite/pull/13893#issuecomment-1678628198
19231923
19241924 if ( config . build . cssMinify === 'lightningcss' ) {
1925- const { code, warnings } = ( await importLightningCSS ( ) ) . transform ( {
1926- ...config . css . lightningcss ,
1927- targets : convertTargets ( config . build . cssTarget ) ,
1928- cssModules : undefined ,
1929- // TODO: Pass actual filename here, which can also be passed to esbuild's
1930- // `sourcefile` option below to improve error messages
1931- filename : defaultCssBundleName ,
1932- code : Buffer . from ( css ) ,
1933- minify : true ,
1934- } )
1935- if ( warnings . length ) {
1936- config . logger . warn (
1937- colors . yellow (
1938- `warnings when minifying css:\n${ warnings
1939- . map ( ( w ) => w . message )
1940- . join ( '\n' ) } `,
1941- ) ,
1942- )
1943- }
1925+ try {
1926+ const { code, warnings } = ( await importLightningCSS ( ) ) . transform ( {
1927+ ...config . css . lightningcss ,
1928+ targets : convertTargets ( config . build . cssTarget ) ,
1929+ cssModules : undefined ,
1930+ // TODO: Pass actual filename here, which can also be passed to esbuild's
1931+ // `sourcefile` option below to improve error messages
1932+ filename : defaultCssBundleName ,
1933+ code : Buffer . from ( css ) ,
1934+ minify : true ,
1935+ } )
1936+ if ( warnings . length ) {
1937+ const messages = warnings . map (
1938+ ( warning ) =>
1939+ `${ warning . message } \n` +
1940+ generateCodeFrame ( css , {
1941+ line : warning . loc . line ,
1942+ column : warning . loc . column - 1 , // 1-based
1943+ } ) ,
1944+ )
1945+ config . logger . warn (
1946+ colors . yellow ( `warnings when minifying css:\n${ messages . join ( '\n' ) } ` ) ,
1947+ )
1948+ }
19441949
1945- // NodeJS res.code = Buffer
1946- // Deno res.code = Uint8Array
1947- // For correct decode compiled css need to use TextDecoder
1948- // LightningCSS output does not return a linebreak at the end
1949- return decoder . decode ( code ) + ( inlined ? '' : '\n' )
1950+ // NodeJS res.code = Buffer
1951+ // Deno res.code = Uint8Array
1952+ // For correct decode compiled css need to use TextDecoder
1953+ // LightningCSS output does not return a linebreak at the end
1954+ return decoder . decode ( code ) + ( inlined ? '' : '\n' )
1955+ } catch ( e ) {
1956+ e . message = `[lightningcss minify] ${ e . message } `
1957+ if ( e . loc ) {
1958+ e . loc = {
1959+ line : e . loc . line ,
1960+ column : e . loc . column - 1 , // 1-based
1961+ }
1962+ e . frame = generateCodeFrame ( css , e . loc )
1963+ }
1964+ throw e
1965+ }
19501966 }
19511967 try {
19521968 const { code, warnings } = await transform ( css , {
@@ -3231,6 +3247,15 @@ async function compileLightningCSS(
32313247 throw e
32323248 }
32333249
3250+ for ( const warning of res . warnings ) {
3251+ let msg = `[vite:css][lightningcss] ${ warning . message } `
3252+ msg += `\n${ generateCodeFrame ( src , {
3253+ line : warning . loc . line ,
3254+ column : warning . loc . column - 1 , // 1-based
3255+ } ) } `
3256+ environment . logger . warn ( colors . yellow ( msg ) )
3257+ }
3258+
32343259 // NodeJS res.code = Buffer
32353260 // Deno res.code = Uint8Array
32363261 // For correct decode compiled css need to use TextDecoder
0 commit comments