add logs when the desktop or fullstack application is collecting assets
This commit is contained in:
1 parent
b76f129083
commit
426a342700
8 files changed
+82
No files matched your search
@@ -12,6 +12,10 @@ pub fn copy_assets() {
|
|||||||
)
|
)
|
||||||
))]
|
))]
|
||||||
{
|
{
|
||||||
|
// The CLI will copy assets to the current working directory
|
||||||
|
if std::env::var_os("DIOXUS_ACTIVE").is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
use manganis_cli_support::AssetManifest;
|
use manganis_cli_support::AssetManifest;
|
||||||
use manganis_cli_support::AssetManifestExt;
|
use manganis_cli_support::AssetManifestExt;
|
||||||
use manganis_cli_support::Config;
|
use manganis_cli_support::Config;
|
||||||
@@ -21,6 +25,7 @@ pub fn copy_assets() {
|
|||||||
let asset_location = PathBuf::from(asset_location);
|
let asset_location = PathBuf::from(asset_location);
|
||||||
let _ = std::fs::remove_dir_all(&asset_location);
|
let _ = std::fs::remove_dir_all(&asset_location);
|
||||||
|
|
||||||
|
println!("Finding assets... (Note: if you run a dioxus desktop application with the CLI. This process will be significantly faster.)");
|
||||||
let manifest = AssetManifest::load();
|
let manifest = AssetManifest::load();
|
||||||
let has_assets = manifest
|
let has_assets = manifest
|
||||||
.packages()
|
.packages()
|
||||||
@@ -31,6 +36,8 @@ pub fn copy_assets() {
|
|||||||
println!("Copying and optimizing assets...");
|
println!("Copying and optimizing assets...");
|
||||||
manifest.copy_static_assets_to(&asset_location).unwrap();
|
manifest.copy_static_assets_to(&asset_location).unwrap();
|
||||||
println!("Copied assets to {}", asset_location.display());
|
println!("Copied assets to {}", asset_location.display());
|
||||||
|
} else {
|
||||||
|
println!("No assets found");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[cfg(not(all(
|
#[cfg(not(all(
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ dioxus-hot-reload = { workspace = true }
|
|||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
|
web-sys = { version = "0.3.61", features = ["Window", "Document", "Element", "HtmlDocument", "Storage", "console"] }
|
||||||
|
|
||||||
|
[target.'cfg(any(target_os = "windows",target_os = "macos",target_os = "linux",target_os = "dragonfly", target_os = "freebsd", target_os = "netbsd", target_os = "openbsd"))'.dependencies]
|
||||||
|
# This is only for debug mode, and it appears mobile does not support some packages this uses
|
||||||
|
manganis-cli-support = { git = "https://github.com/DioxusLabs/collect-assets", features = ["webp", "html"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["hot-reload", "default-tls"]
|
default = ["hot-reload", "default-tls"]
|
||||||
router = ["dioxus-router"]
|
router = ["dioxus-router"]
|
||||||
|
|||||||
@@ -277,6 +277,9 @@ where
|
|||||||
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
||||||
use tower_http::services::{ServeDir, ServeFile};
|
use tower_http::services::{ServeDir, ServeFile};
|
||||||
|
|
||||||
|
// Copy over any assets we find
|
||||||
|
crate::collect_assets::copy_assets();
|
||||||
|
|
||||||
let assets_path = assets_path.into();
|
let assets_path = assets_path.into();
|
||||||
|
|
||||||
// Serve all files in dist folder except index.html
|
// Serve all files in dist folder except index.html
|
||||||
|
|||||||
@@ -241,6 +241,9 @@ impl DioxusRouterExt for Router {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
fn serve_static_assets(mut self, assets_path: impl Into<std::path::PathBuf>) -> Self {
|
||||||
|
// Copy over any assets we find
|
||||||
|
crate::collect_assets::copy_assets();
|
||||||
|
|
||||||
let assets_path = assets_path.into();
|
let assets_path = assets_path.into();
|
||||||
|
|
||||||
// Serve all files in dist folder except index.html
|
// Serve all files in dist folder except index.html
|
||||||
|
|||||||
@@ -187,6 +187,9 @@ pub fn serve_dioxus_application<P: Clone + serde::Serialize + Send + Sync + 'sta
|
|||||||
// Serve the dist folder and the index.html file
|
// Serve the dist folder and the index.html file
|
||||||
let serve_dir = warp::fs::dir(cfg.assets_path);
|
let serve_dir = warp::fs::dir(cfg.assets_path);
|
||||||
|
|
||||||
|
// Copy over any assets we find
|
||||||
|
crate::collect_assets::copy_assets();
|
||||||
|
|
||||||
connect_hot_reload()
|
connect_hot_reload()
|
||||||
// First register the server functions
|
// First register the server functions
|
||||||
.or(register_server_fns(server_fn_route))
|
.or(register_server_fns(server_fn_route))
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
pub fn copy_assets() {
|
||||||
|
#[cfg(all(
|
||||||
|
debug_assertions,
|
||||||
|
any(
|
||||||
|
target_os = "windows",
|
||||||
|
target_os = "macos",
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
)
|
||||||
|
))]
|
||||||
|
{
|
||||||
|
// The CLI will copy assets to the current working directory
|
||||||
|
if std::env::var_os("DIOXUS_ACTIVE").is_some() {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
use manganis_cli_support::AssetManifest;
|
||||||
|
use manganis_cli_support::AssetManifestExt;
|
||||||
|
use manganis_cli_support::Config;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
let config = Config::current();
|
||||||
|
let asset_location = config.assets_serve_location();
|
||||||
|
let asset_location = PathBuf::from(asset_location);
|
||||||
|
let _ = std::fs::remove_dir_all(&asset_location);
|
||||||
|
|
||||||
|
println!("Finding assets... (Note: if you run a dioxus desktop application with the CLI. This process will be significantly faster.)");
|
||||||
|
let manifest = AssetManifest::load();
|
||||||
|
let has_assets = manifest
|
||||||
|
.packages()
|
||||||
|
.iter()
|
||||||
|
.any(|package| !package.assets().is_empty());
|
||||||
|
|
||||||
|
if has_assets {
|
||||||
|
println!("Copying and optimizing assets...");
|
||||||
|
manifest.copy_static_assets_to(&asset_location).unwrap();
|
||||||
|
println!("Copied assets to {}", asset_location.display());
|
||||||
|
} else {
|
||||||
|
println!("No assets found");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(not(all(
|
||||||
|
debug_assertions,
|
||||||
|
any(
|
||||||
|
target_os = "windows",
|
||||||
|
target_os = "macos",
|
||||||
|
target_os = "linux",
|
||||||
|
target_os = "dragonfly",
|
||||||
|
target_os = "freebsd",
|
||||||
|
target_os = "netbsd",
|
||||||
|
target_os = "openbsd"
|
||||||
|
)
|
||||||
|
)))]
|
||||||
|
{
|
||||||
|
println!(
|
||||||
|
"Skipping assets in release mode. You compile assets with the dioxus-cli in release mode"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ pub mod router;
|
|||||||
mod adapters;
|
mod adapters;
|
||||||
#[cfg(feature = "ssr")]
|
#[cfg(feature = "ssr")]
|
||||||
pub use adapters::*;
|
pub use adapters::*;
|
||||||
|
mod collect_assets;
|
||||||
mod hooks;
|
mod hooks;
|
||||||
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
#[cfg(all(debug_assertions, feature = "hot-reload", feature = "ssr"))]
|
||||||
mod hot_reload;
|
mod hot_reload;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@
|
|||||||
// - Do DOM work in the next requestAnimationFrame callback
|
// - Do DOM work in the next requestAnimationFrame callback
|
||||||
|
|
||||||
pub use crate::cfg::Config;
|
pub use crate::cfg::Config;
|
||||||
|
#[cfg(feature = "file_engine")]
|
||||||
pub use crate::file_engine::WebFileEngineExt;
|
pub use crate::file_engine::WebFileEngineExt;
|
||||||
use dioxus_core::{Element, Scope, VirtualDom};
|
use dioxus_core::{Element, Scope, VirtualDom};
|
||||||
use futures_util::{
|
use futures_util::{
|
||||||
|
|||||||
Reference in new issue
Block a user