dioxus/examples/custom_assets.rs

28 lines
843 B
Rust
Raw Normal View History

2024-02-14 12:33:07 -08:00
//! A simple example on how to use assets loading from the filesystem.
//!
//! If the feature "collect-assets" is enabled, the assets will be collected via the dioxus CLI and embedded into the
//! final bundle. This lets you do various useful things like minify, compress, and optimize your assets.
//!
//! We can still use assets without the CLI middleware, but generally larger apps will benefit from it.
2022-01-27 16:36:17 -05:00
use dioxus::prelude::*;
2024-01-18 12:36:42 -08:00
#[cfg(not(feature = "collect-assets"))]
static ASSET_PATH: &str = "examples/assets/logo.png";
#[cfg(feature = "collect-assets")]
static ASSET_PATH: &str = asset!("examples/assets/logo.png".format(ImageType::Avif));
2024-01-18 12:36:42 -08:00
2022-01-27 16:36:17 -05:00
fn main() {
2024-01-20 00:11:55 -08:00
launch(app);
2022-01-27 16:36:17 -05:00
}
fn app() -> Element {
2024-01-16 13:18:46 -06:00
rsx! {
2022-01-27 16:36:17 -05:00
div {
2024-02-14 12:33:07 -08:00
h1 { "This should show an image:" }
2024-01-18 12:36:42 -08:00
img { src: ASSET_PATH.to_string() }
2022-01-27 16:36:17 -05:00
}
2024-01-13 21:12:21 -08:00
}
2022-01-27 16:36:17 -05:00
}