@@ -1480,7 +1480,7 @@ async function compileCSS(
1480
1480
}
1481
1481
} else if ( message . type === 'warning' ) {
1482
1482
const warning = message as PostCSS . Warning
1483
- let msg = `[vite:css] ${ warning . text } `
1483
+ let msg = `[vite:css][postcss] ${ warning . text } `
1484
1484
msg += `\n${ generateCodeFrame (
1485
1485
code ,
1486
1486
{
@@ -1922,31 +1922,47 @@ async function minifyCSS(
1922
1922
// See https://github.com/vitejs/vite/pull/13893#issuecomment-1678628198
1923
1923
1924
1924
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
+ }
1944
1949
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
+ }
1950
1966
}
1951
1967
try {
1952
1968
const { code, warnings } = await transform ( css , {
@@ -3231,6 +3247,15 @@ async function compileLightningCSS(
3231
3247
throw e
3232
3248
}
3233
3249
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
+
3234
3259
// NodeJS res.code = Buffer
3235
3260
// Deno res.code = Uint8Array
3236
3261
// For correct decode compiled css need to use TextDecoder
0 commit comments