10 releases

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

#339 in Build Utils

Download history 790/week @ 2024-08-19 1025/week @ 2024-08-26 1001/week @ 2024-09-02 1086/week @ 2024-09-09 1331/week @ 2024-09-16 1095/week @ 2024-09-23 939/week @ 2024-09-30 1123/week @ 2024-10-07 1375/week @ 2024-10-14 969/week @ 2024-10-21 635/week @ 2024-10-28 478/week @ 2024-11-04 512/week @ 2024-11-11 498/week @ 2024-11-18 513/week @ 2024-11-25 377/week @ 2024-12-02

1,947 downloads per month

MIT/Apache and GPL-3.0-or-later

90KB
2K 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};
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();

// Tell manganis that you support assets
let _guard = ManganisSupportGuard::default();

// Determine if Rust is trying to link:
if let Some((_working_dir, object_files)) = manganis_cli_support::linker_intercept(std::env::args()) {
    // If it is, collect the assets.
    let manifest = AssetManifest::load(object_files);

    // 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();
    
} else {
    // If it isn't, build your app and initiate the helper function `start_linker_intercept()`

    // Put any cargo args in a slice that should also be passed 
    // to manganis toreproduce the same build. e.g. the `--release` flag
    let args: Vec<&str> = vec![];
    Command::new("cargo")
        .arg("build")
        .args(args.clone())
        .spawn()
        .unwrap()
        .wait()
        .unwrap();

    manganis_cli_support::start_linker_intercept(None, args).unwrap();
}

Dependencies

~75MB
~1.5M SLoC