9 releases

new 0.3.0-alpha.3 Oct 14, 2024
0.3.0-alpha.2 Sep 3, 2024
0.3.0-alpha.1 Aug 7, 2024
0.3.0-alpha.0 Jul 31, 2024
0.1.1 Feb 22, 2024

#71 in Build Utils

Download history 498/week @ 2024-06-27 368/week @ 2024-07-04 475/week @ 2024-07-11 617/week @ 2024-07-18 409/week @ 2024-07-25 1027/week @ 2024-08-01 1128/week @ 2024-08-08 862/week @ 2024-08-15 708/week @ 2024-08-22 1069/week @ 2024-08-29 939/week @ 2024-09-05 1124/week @ 2024-09-12 845/week @ 2024-09-19 1059/week @ 2024-09-26 861/week @ 2024-10-03 997/week @ 2024-10-10

3,945 downloads per month
Used in 2 crates

MIT/Apache and maybe GPL-3.0-or-later

23KB
202 lines

Manganis

The Manganis allows you to submit assets to a build tool that supports collecting assets. It makes it easy to self-host assets that are distributed throughout your library. Manganis also handles optimizing, converting, and fetching assets.

If you defined this in a component library:

const AVIF_ASSET: &str = manganis::mg!("rustacean-flat-gesture.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.

// You can include tailwind classes that will be collected into the final binary
const TAILWIND_CLASSES: &str = manganis::classes!("flex flex-col p-5");

// You can also collect arbitrary files. Relative paths are resolved relative to the package root
const _: &str = manganis::mg!("test-package-dependency/src/asset.txt"); 
// You can use URLs to copy read the asset at build time
const _: &str = manganis::mg!("https://rustacean.net/assets/rustacean-flat-happy.png");

// You can collect images which will be automatically optimized
pub const PNG_ASSET: manganis::ImageAsset =
    manganis::mg!(image("rustacean-flat-gesture.png"));
// Resize the image at compile time to make the assets smaller
pub const RESIZED_PNG_ASSET: manganis::ImageAsset =
    manganis::mg!(image("rustacean-flat-gesture.png").size(52, 52));
// Or convert the image at compile time to a web friendly format
pub const AVIF_ASSET: manganis::ImageAsset = manganis::mg!(image("rustacean-flat-gesture.png")
    .format(ImageType::Avif));
// You can even include a low quality preview of the image embedded into the url
pub const AVIF_ASSET_LOW: manganis::ImageAsset = manganis::mg!(image("rustacean-flat-gesture.png")
	.format(ImageType::Avif)
	.low_quality_preview());

// You can also collect google fonts
pub const ROBOTO_FONT: &str = manganis::mg!(font()
    .families(["Roboto"]));
// Specify weights for fonts to collect
pub const COMFORTAA_FONT: &str = manganis::mg!(font()
    .families(["Comfortaa"])
    .weights([400]));
// Or specific text to include only the characters used in that text
pub const ROBOTO_FONT_LIGHT_FONT: &str = manganis::mg!(font()
    .families(["Roboto"])
    .weights([200])
    .text("hello world"));

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–19MB
~284K SLoC