custom_assets.rs 851 B

123456789101112131415161718192021222324252627
  1. //! A simple example on how to use assets loading from the filesystem.
  2. //!
  3. //! If the feature "collect-assets" is enabled, the assets will be collected via the dioxus CLI and embedded into the
  4. //! final bundle. This lets you do various useful things like minify, compress, and optimize your assets.
  5. //!
  6. //! We can still use assets without the CLI middleware, but generally larger apps will benefit from it.
  7. use dioxus::prelude::*;
  8. #[cfg(not(feature = "collect-assets"))]
  9. static ASSET_PATH: &str = "examples/assets/logo.png";
  10. #[cfg(feature = "collect-assets")]
  11. static ASSET_PATH: &str = asset!("examples/assets/logo.png".format(ImageType::Avif));
  12. fn main() {
  13. dioxus::launch(app);
  14. }
  15. fn app() -> Element {
  16. rsx! {
  17. div {
  18. h1 { "This should show an image:" }
  19. img { src: ASSET_PATH.to_string() }
  20. }
  21. }
  22. }