Expand description
§Manganis
The Manganis allows you to submit assets to any build tool that supports collecting assets. It makes it easy to self-host assets that are distributed throughout your libraries. Manganis also handles optimizing, converting, and fetching assets.
If you defined this in a component library:
use manganis::{Asset, asset};
const AVIF_ASSET: Asset = manganis::asset!("/assets/image.png");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.
If you have assets that may not always be bundled, you can fall back gracefully with option_asset!:
use manganis::{Asset, asset, option_asset};
const REQUIRED: Asset = asset!("/assets/style.css");
const OPTIONAL: Option<Asset> = option_asset!("/assets/missing.css");use manganis::{ImageFormat, Asset, asset, ImageSize, AssetOptions};
// You can collect arbitrary files. Absolute paths are resolved relative to the package root
const _: Asset = asset!("/assets/script.js");
// You can collect images which will be automatically optimized
pub const PNG_ASSET: Asset =
asset!("/assets/image.png");
// Resize the image at compile time to make the assets smaller
pub const RESIZED_PNG_ASSET: Asset =
asset!("/assets/image.png", AssetOptions::image().with_size(ImageSize::Manual { width: 52, height: 52 }));
// Or convert the image at compile time to a web friendly format
pub const AVIF_ASSET: Asset = asset!("/assets/image.png", AssetOptions::image().with_format(ImageFormat::Avif));§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.
Macros§
- asset
- The asset macro collects assets that will be included in the final binary
- option_
asset - Resolve an asset at compile time, returning
Noneif the asset does not exist.
Structs§
- Asset
- A bundled asset with some options. The asset can be used in rsx! to reference the asset.
It should not be read directly with
std::fs::readbecause the path needs to be resolved relative to the bundle - Asset
Options - Settings for a generic asset
- Bundled
Asset - An asset that should be copied by the bundler with some options. This type will be
serialized into the binary.
CLIs that support manganis, should pull out the assets from the link section, optimize,
and write them to the filesystem at
BundledAsset::bundled_pathfor the application to use. - CssAsset
Options - Options for a css asset
- Folder
Asset Options - The builder for a folder asset.
- Image
Asset Options - Options for an image asset
- JsAsset
Options - Options for a javascript asset
Enums§
- Asset
Variant - Settings for a specific type of asset
- Image
Format - The type of an image. You can read more about the tradeoffs between image formats here
- Image
Size - The size of an image asset