dioxus/examples/custom_assets.rs
Evan Almloff c6a2e5b6c8
Use head elements and new manganis syntax in examples (#2688)
* use head elements and new manganis syntax in examples
* only enable desktop workspace example scraping during a dioxus release

---------

Co-authored-by: Jonathan Kelley <jkelleyrtp@gmail.com>
2024-07-25 21:58:00 +00:00

27 lines
843 B
Rust

//! 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.
use dioxus::prelude::*;
#[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));
fn main() {
launch(app);
}
fn app() -> Element {
rsx! {
div {
h1 { "This should show an image:" }
img { src: ASSET_PATH.to_string() }
}
}
}