@@ -8,26 +8,18 @@ use std::{fmt, str};
8
8
9
9
pub ( crate ) struct StaticFile {
10
10
pub ( crate ) filename : PathBuf ,
11
- pub ( crate ) bytes : & ' static [ u8 ] ,
11
+ pub ( crate ) src_bytes : & ' static [ u8 ] ,
12
+ pub ( crate ) minified_bytes : & ' static [ u8 ] ,
12
13
}
13
14
14
15
impl 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 }
31
23
}
32
24
33
25
pub ( crate ) fn output_filename ( & self ) -> & Path {
@@ -68,7 +60,7 @@ macro_rules! static_files {
68
60
69
61
// sha256 files are generated in build.rs
70
62
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" ) ) ) , ) +
72
64
} ) ;
73
65
74
66
pub ( crate ) fn for_each<E >( f: impl Fn ( & StaticFile ) -> Result <( ) , E >) -> Result <( ) , E > {
0 commit comments