#assets

build manganis

Ergonomic, automatic, cross crate asset collection and optimization

27 releases

0.7.2 Dec 5, 2025
0.7.1 Nov 6, 2025
0.7.0 Oct 31, 2025
0.7.0-alpha.3 Jul 17, 2025
0.2.2 Mar 25, 2024

#64 in Build Utils

Download history 7800/week @ 2025-08-27 7601/week @ 2025-09-03 8121/week @ 2025-09-10 8464/week @ 2025-09-17 8469/week @ 2025-09-24 9648/week @ 2025-10-01 9322/week @ 2025-10-08 11992/week @ 2025-10-15 9953/week @ 2025-10-22 10863/week @ 2025-10-29 13277/week @ 2025-11-05 11396/week @ 2025-11-12 11736/week @ 2025-11-19 10689/week @ 2025-11-26 13672/week @ 2025-12-03 10916/week @ 2025-12-10

48,768 downloads per month
Used in 5 crates

MIT/Apache

13KB
90 lines

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.

Dependencies

~0.4–1MB
~24K SLoC