15 unstable releases (3 breaking)

0.6.2 Jan 22, 2025
0.6.1 Dec 18, 2024
0.6.0-alpha.5 Nov 16, 2024
0.3.0-alpha.0 Jul 31, 2024
0.2.2 Mar 25, 2024

#77 in Build Utils

Download history 923/week @ 2024-10-27 845/week @ 2024-11-03 734/week @ 2024-11-10 1193/week @ 2024-11-17 1238/week @ 2024-11-24 1530/week @ 2024-12-01 2866/week @ 2024-12-08 3390/week @ 2024-12-15 2008/week @ 2024-12-22 2107/week @ 2024-12-29 3390/week @ 2025-01-05 3686/week @ 2025-01-12 4483/week @ 2025-01-19 4020/week @ 2025-01-26 3637/week @ 2025-02-02 4506/week @ 2025-02-09

16,949 downloads per month
Used in 3 crates

MIT/Apache

18KB
216 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
~22K SLoC