dioxus/examples/custom_assets.rs

28 lines
843 B
Rust
Raw Normal View History

2024-02-14 20:33:07 +00: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 21:36:17 +00:00
use dioxus::prelude::*;
2024-01-18 20:36:42 +00: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 20:36:42 +00:00
2022-01-27 21:36:17 +00:00
fn main() {
2024-01-20 08:11:55 +00:00
launch(app);
2022-01-27 21:36:17 +00:00
}
fn app() -> Element {
2024-01-16 19:18:46 +00:00
rsx! {
2022-01-27 21:36:17 +00:00
div {
2024-02-14 20:33:07 +00:00
h1 { "This should show an image:" }
2024-01-18 20:36:42 +00:00
img { src: ASSET_PATH.to_string() }
2022-01-27 21:36:17 +00:00
}
2024-01-14 05:12:21 +00:00
}
2022-01-27 21:36:17 +00:00
}