Crate manganis_cli_support

Source
Expand description

§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();
}

Structs§

AssetManifest
A manifest of all assets collected from dependencies
Config
The configuration for collecting assets
CssOptions
The options for a css asset
FileAsset
A file asset
FileLocation
The location of an asset before and after it is collected
FontOptions
The options for a font asset
ImageOptions
The options for an image asset
ManganisSupportGuard
This guard tells the marco that the application is being compiled with a CLI that supports assets
MetadataAsset
A metadata asset
PackageAssets
All assets collected from a specific package
TailwindAsset
A tailwind class asset
TailwindWarning
UnknownFileOptions
The options for an unknown file asset
VideoOptions
The options for a video asset

Enums§

AssetType
The type of asset
FileOptions
The options for a file asset
FileSource
The source of a file asset
FontType
The type of a font
ImageType
The type of an image
VideoType
The type of a video

Traits§

AssetManifestExt
An extension trait CLI support for the asset manifest

Functions§

add_asset
Adds an asset to the current package
clear_assets
Clears all assets from the current package
get_mime_from_ext
Get the mime type from a URI using its extension
process_file
Process a specific file asset