13 unstable releases (3 breaking)

new 0.6.0 Dec 7, 2024
0.6.0-alpha.5 Nov 16, 2024
0.3.0-alpha.0 Jul 31, 2024
0.2.2 Mar 25, 2024

#108 in Build Utils

Download history 756/week @ 2024-08-19 829/week @ 2024-08-26 1161/week @ 2024-09-02 828/week @ 2024-09-09 1159/week @ 2024-09-16 996/week @ 2024-09-23 959/week @ 2024-09-30 839/week @ 2024-10-07 1378/week @ 2024-10-14 1002/week @ 2024-10-21 888/week @ 2024-10-28 833/week @ 2024-11-04 802/week @ 2024-11-11 1163/week @ 2024-11-18 1216/week @ 2024-11-25 1778/week @ 2024-12-02

5,045 downloads per month
Used in 2 crates

MIT/Apache

16KB
193 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