Only compress web assets in the CLI (#2329)
* only compress web assets in the CLI * precompressed -> pre-compressed * only enable pre-compression in release builds
This commit is contained in:
1 parent
b147f5a737
commit
a27d4e71ed
13 files changed
+461
-468
No files matched your search
@@ -207,6 +207,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
// TODO: This is a breaking change, but we should probably serve static assets from a different directory than dist where the server executable is located
|
||||
// This would prevent issues like https://github.com/DioxusLabs/dioxus/issues/2327
|
||||
fn serve_static_assets(
|
||||
mut self,
|
||||
assets_path: impl Into<std::path::PathBuf>,
|
||||
@@ -215,11 +217,6 @@ where
|
||||
|
||||
let assets_path = assets_path.into();
|
||||
async move {
|
||||
#[cfg(not(debug_assertions))]
|
||||
if let Err(err) = crate::assets::pre_compress_files(assets_path.clone()).await {
|
||||
tracing::error!("Failed to pre-compress static assets: {}", err);
|
||||
}
|
||||
|
||||
// Serve all files in dist folder except index.html
|
||||
let dir = std::fs::read_dir(&assets_path).unwrap_or_else(|e| {
|
||||
panic!(
|
||||
@@ -246,9 +243,9 @@ where
|
||||
.join("/");
|
||||
let route = format!("/{}", route);
|
||||
if path.is_dir() {
|
||||
self = self.nest_service(&route, ServeDir::new(path).precompressed_gzip());
|
||||
self = self.nest_service(&route, ServeDir::new(path).precompressed_br());
|
||||
} else {
|
||||
self = self.nest_service(&route, ServeFile::new(path).precompressed_gzip());
|
||||
self = self.nest_service(&route, ServeFile::new(path).precompressed_br());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user