1
0

custom_assets.rs 868 B

12345678910111213141516171819202122232425262728
  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 =
  12. manganis::mg!(image("examples/assets/logo.png").format(ImageType::Avif)).path();
  13. fn main() {
  14. launch(app);
  15. }
  16. fn app() -> Element {
  17. rsx! {
  18. div {
  19. h1 { "This should show an image:" }
  20. img { src: ASSET_PATH.to_string() }
  21. }
  22. }
  23. }