Manganis
The Manganis allows you to submit assets to a build tool that supports collecting assets. It makes it easy to self-host assets that are distributed throughout your library. Manganis also handles optimizing, converting, and fetching assets.
If you defined this in a component library:
const AVIF_ASSET: &str = file!;
AVIF_ASSET will be set to a new file name that will be served by some CLI. That file can be collected by any package that depends on the component library.
// You can include tailwind classes that will be collected into the final binary
const TAILWIND_CLASSES: &str = classes!;
// You can also collect arbitrary files. Relative paths are resolved relative to the package root
const _: &str = mg!;
// You can use URLs to copy read the asset at build time
const _: &str = mg!;
// You can collect images which will be automatically optimized
pub const RESIZED_PNG_ASSET: ImageAsset =
mg!;
// Resize the image at compile time to make the assets smaller
pub const RESIZED_PNG_ASSET: ImageAsset =
mg!;
// Or convert the image at compile time to a web friendly format
pub const AVIF_ASSET: ImageAsset = mg!;
// You can even include a low quality preview of the image embedded into the url
pub const AVIF_ASSET: ImageAsset = mg!;
// You can also collect google fonts
pub const ROBOTO_FONT: &str = mg!;
// Specify weights for fonts to collect
pub const COMFORTAA_FONT: &str = mg!;
// Or specific text to include only the characters used in that text
pub const ROBOTO_FONT_LIGHT_FONT: &str = mg!;
Adding Support to Your CLI
To add support for your CLI, you need to integrate with the manganis_cli_support crate. This crate provides utilities to collect assets that integrate with the Manganis macro. It makes it easy to integrate an asset collection and optimization system into a build tool.