16 unstable releases (4 breaking)

0.7.0-alpha.0 May 14, 2025
0.6.2 Jan 22, 2025
0.6.1 Dec 18, 2024
0.6.0-alpha.5 Nov 16, 2024
0.2.2 Mar 25, 2024

#226 in Rust patterns

Download history 4078/week @ 2025-02-04 4704/week @ 2025-02-11 4560/week @ 2025-02-18 4302/week @ 2025-02-25 4001/week @ 2025-03-04 5239/week @ 2025-03-11 4803/week @ 2025-03-18 5090/week @ 2025-03-25 5167/week @ 2025-04-01 5062/week @ 2025-04-08 3904/week @ 2025-04-15 5407/week @ 2025-04-22 5411/week @ 2025-04-29 4882/week @ 2025-05-06 4379/week @ 2025-05-13 3885/week @ 2025-05-20

19,357 downloads per month
Used in 2 crates

MIT/Apache

20KB
261 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.

use manganis::{ImageFormat, ImageAssetOptions, Asset, asset, ImageSize};
// 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", ImageAssetOptions::new().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", ImageAssetOptions::new().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
~23K SLoC

OSZAR »