DioxusLabs / DioxusLabs/dioxus
Asset optimization config for indirectly referenced assets
- Dominant language
- Rust
- Stars
- 39.1k
- Forks
- 1.9k
- Avg merge
- 4d 10h
- Merged PRs (30d)
- 4
Description
## Feature Request
All asset transformations are currently described in the asset macro itself. This is nice because it natively gives us autocomplete, documentation, and lets you share configs between multiple asset with `const`. However, we currently don't have a way define how asset linked to inside of a folder or referenced from other asset (#5452) are optimized.
## Implement Suggestion
A few different designs:
- Add this to the dioxus.toml with a json schema for autocomplete
```toml
[assets.optimize]
glob = "**/*icon*.png"
img.avif = true
img.size.x = 24
img.size.y = 24
[assets.optimize]
glob = "**.jpeg"
img.avif = true
```
This would require a different toml syntax for asset options which would be difficult to find from docs.rs
- Define asset optimizations where you pull in the asset (folder, css links, etc)
```rust
asset!("style.css", AssetOptions::css().optimize_references(AssetManifest()
.or(AssetMatch::glob("**/*icon*.png").optimize(OPTIMIZED_IMAGE)),
.or(AssetMatch::glob("**.jpeg").optimize(AssetOptions::img().with_avif()))
```
This would be nice for assets that you only reference in one place and make it easy to see what config is effecting which asset, but potentially cause issues if things like icons are referenced from multiple different assets
- Add a new global manganis manifest macro that can only be defined in the main crate
```rust
const OPTIMIZED_IMAGE = AssetOptions::img().with_avif().with_size(24, 24);
asset_manifest!(AssetManifest()
.or(AssetMatch::glob("**/*icon*.png").optimize(OPTIMIZED_IMAGE))
.or(AssetMatch::glob("**.jpeg").optimize(AssetOptions::img().with_avif()))
)
```
Assets referenced in multiple places would get the same config and the types stay in rust.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.