@@ -6,6 +6,9 @@ use std::{
6
6
use colored:: Colorize ;
7
7
use eyre:: { bail, eyre, Result , WrapErr } ;
8
8
use futures_util:: { self , StreamExt } ;
9
+ use lightningcss:: stylesheet:: {
10
+ StyleSheet , ParserOptions , MinifyOptions , PrinterOptions
11
+ } ;
9
12
use rss:: Channel ;
10
13
use tera:: { Context , Tera } ;
11
14
use tokio:: sync:: Mutex ;
@@ -444,18 +447,13 @@ async fn minify_js_asset(src_path: &Path, dest_path: &Path) -> Result<()> {
444
447
/// * `Result<()>` - `Ok(())` if minification and writing succeed, otherwise an error.
445
448
#[ instrument( skip( src_path, dest_path) ) ]
446
449
async fn minify_css_asset ( src_path : & Path , dest_path : & Path ) -> Result < ( ) > {
447
- let content = tokio:: fs:: read_to_string ( src_path) . await ?;
448
- // See https://docs.rs/css-minify/0.5.2/css_minify/optimizations/enum.Level.html#variants
449
- let minified = css_minify:: optimizations:: Minifier :: default ( )
450
- . minify ( & content, css_minify:: optimizations:: Level :: Two )
451
- . map_err ( |e| {
452
- eyre ! (
453
- "{}: {}" ,
454
- format!( "CSS minification failed for {}" , src_path. display( ) ) . bold( ) ,
455
- e
456
- )
457
- } ) ?;
458
- tokio:: fs:: write ( dest_path, minified. into_bytes ( ) )
450
+ let content = tokio:: fs:: read_to_string ( src_path) . await ?. leak ( ) ;
451
+
452
+ let mut stylesheet = StyleSheet :: parse ( content, ParserOptions :: default ( ) ) ?;
453
+ stylesheet. minify ( MinifyOptions :: default ( ) ) ?;
454
+ let minified = stylesheet. to_css ( PrinterOptions { minify : true , ..Default :: default ( ) } ) ?;
455
+
456
+ tokio:: fs:: write ( dest_path, minified. code )
459
457
. await
460
458
. wrap_err_with ( || {
461
459
format ! ( "Failed to write minified CSS to {}" , dest_path. display( ) ) . bold ( )
0 commit comments