#assets #build-tool #optimization #automatic #collection #manganis #cross

build manganis-cli-support

Ergonomic, automatic, cross crate asset collection and optimization

6 releases

0.2.4 Mar 25, 2024
0.2.3 Mar 25, 2024
0.1.1 Feb 22, 2024

#386 in Build Utils

Download history 386/week @ 2024-02-19 210/week @ 2024-02-26 243/week @ 2024-03-04 622/week @ 2024-03-11 382/week @ 2024-03-18 1323/week @ 2024-03-25 953/week @ 2024-04-01 894/week @ 2024-04-08 804/week @ 2024-04-15 734/week @ 2024-04-22 692/week @ 2024-04-29 516/week @ 2024-05-06

2,870 downloads per month
Used in 2 crates

MIT/Apache and GPL-3.0-or-later

61KB
1K SLoC

Manganis CLI Support

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.

use manganis_cli_support::{AssetManifestExt, ManganisSupportGuard};
use manganis_common::{AssetManifest, Config};

fn main() {
    use std::process::Command;

    // This is the location where the assets will be copied to in the filesystem
    let assets_file_location = "./assets";
    // This is the location where the assets will be served from
    let assets_serve_location = "/assets";

    // First set any settings you need for the build
    Config::default()
        .with_assets_serve_location(assets_serve_location)
        .save();

    // Next, tell manganis that you support assets
    let _guard = ManganisSupportGuard::default();

    // Then build your application
    Command::new("cargo")
        .args(["build"])
        .spawn()
        .unwrap()
        .wait()
        .unwrap();

    // Then collect the assets
    let manifest = AssetManifest::load();

    // Remove the old assets
    let _ = std::fs::remove_dir_all(assets_file_location);

    // And copy the static assets to the public directory
    manifest
        .copy_static_assets_to(assets_file_location)
        .unwrap();

    // Then collect the tailwind CSS
    let css = manifest.collect_tailwind_css(true, &mut Vec::new());

    // And write the CSS to the public directory
    std::fs::write(format!("{}/tailwind.css", assets_file_location), css).unwrap();
}

Dependencies

~61MB
~1M SLoC