@@ -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 , {
0 commit comments