mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
Fix extremely slow dev builds caused by embedding + compressing assets at compile time (#1395)
This commit is contained in:
@@ -24,6 +24,7 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
let assets = EmbeddedAssets::new(&dist_dir)?;
|
||||
|
||||
// handle default window icons for Windows targets
|
||||
#[cfg(not(debug_assertions))]
|
||||
let default_window_icon = if cfg!(windows) {
|
||||
let icon_path = config_parent.join("icons/icon.ico").display().to_string();
|
||||
quote!(Some(include_bytes!(#icon_path)))
|
||||
@@ -31,6 +32,10 @@ pub fn context_codegen(data: ContextData) -> Result<TokenStream, EmbeddedAssetsE
|
||||
quote!(None)
|
||||
};
|
||||
|
||||
// in development builds, don't use an icon as it slows down cargo check
|
||||
#[cfg(debug_assertions)]
|
||||
let default_window_icon = quote!(None);
|
||||
|
||||
// double braces are purposeful to force the code into a block expression
|
||||
Ok(quote! {{
|
||||
use ::tauri::api::private::{OnceCell, AsTauriContext};
|
||||
|
||||
@@ -51,6 +51,7 @@ pub enum EmbeddedAssetsError {
|
||||
pub struct EmbeddedAssets(HashMap<AssetKey, (String, Vec<u8>)>);
|
||||
|
||||
impl EmbeddedAssets {
|
||||
#[cfg(not(debug_assertions))]
|
||||
/// Compress a directory of assets, ready to be generated into a [`tauri_api::assets::Assets`].
|
||||
pub fn new(path: &Path) -> Result<Self, EmbeddedAssetsError> {
|
||||
WalkDir::new(&path)
|
||||
@@ -73,6 +74,14 @@ impl EmbeddedAssets {
|
||||
.map(Self)
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
/// A dummy EmbeddedAssets for use during development builds.
|
||||
/// Compressing + including the bytes of assets during development takes a long time.
|
||||
/// On development builds, assets will simply be resolved & fetched from the configured dist folder.
|
||||
pub fn new(_: &Path) -> Result<Self, EmbeddedAssetsError> {
|
||||
Ok(EmbeddedAssets(HashMap::new()))
|
||||
}
|
||||
|
||||
/// Use highest compression level for release, the fastest one for everything else
|
||||
fn compression_level() -> i32 {
|
||||
match var("PROFILE").as_ref().map(String::as_str) {
|
||||
|
||||
Reference in New Issue
Block a user