@@ -8,26 +8,18 @@ use std::{fmt, str};
88
99pub ( crate ) struct StaticFile {
1010 pub ( crate ) filename : PathBuf ,
11- pub ( crate ) bytes : & ' static [ u8 ] ,
11+ pub ( crate ) src_bytes : & ' static [ u8 ] ,
12+ pub ( crate ) minified_bytes : & ' static [ u8 ] ,
1213}
1314
1415impl StaticFile {
15- fn new ( filename : & str , bytes : & ' static [ u8 ] , sha256 : & ' static str ) -> StaticFile {
16- Self { filename : static_filename ( filename, sha256) , bytes }
17- }
18-
19- pub ( crate ) fn minified ( & self ) -> Vec < u8 > {
20- let extension = match self . filename . extension ( ) {
21- Some ( e) => e,
22- None => return self . bytes . to_owned ( ) ,
23- } ;
24- if extension == "css" {
25- minifier:: css:: minify ( str:: from_utf8 ( self . bytes ) . unwrap ( ) ) . unwrap ( ) . to_string ( ) . into ( )
26- } else if extension == "js" {
27- minifier:: js:: minify ( str:: from_utf8 ( self . bytes ) . unwrap ( ) ) . to_string ( ) . into ( )
28- } else {
29- self . bytes . to_owned ( )
30- }
16+ fn new (
17+ filename : & str ,
18+ src_bytes : & ' static [ u8 ] ,
19+ minified_bytes : & ' static [ u8 ] ,
20+ sha256 : & ' static str ,
21+ ) -> StaticFile {
22+ Self { filename : static_filename ( filename, sha256) , src_bytes, minified_bytes }
3123 }
3224
3325 pub ( crate ) fn output_filename ( & self ) -> & Path {
@@ -68,7 +60,7 @@ macro_rules! static_files {
6860
6961 // sha256 files are generated in build.rs
7062 pub ( crate ) static STATIC_FILES : std:: sync:: LazyLock <StaticFiles > = std:: sync:: LazyLock :: new( || StaticFiles {
71- $( $field: StaticFile :: new( $file_path, include_bytes!( $file_path) , include_str!( concat!( env!( "OUT_DIR" ) , "/" , $file_path, ".sha256" ) ) ) , ) +
63+ $( $field: StaticFile :: new( $file_path, include_bytes!( $file_path) , include_bytes! ( concat! ( env! ( "OUT_DIR" ) , "/" , $file_path , ".min" ) ) , include_str!( concat!( env!( "OUT_DIR" ) , "/" , $file_path, ".sha256" ) ) ) , ) +
7264 } ) ;
7365
7466 pub ( crate ) fn for_each<E >( f: impl Fn ( & StaticFile ) -> Result <( ) , E >) -> Result <( ) , E > {
0 commit comments