8 个版本

0.3.0-alpha.12024年8月7日
0.3.0-alpha.02024年7月31日
0.2.4 2024年3月25日
0.1.1 2024年2月22日

#633 in 网页编程

Download history 662/week @ 2024-05-01 517/week @ 2024-05-08 688/week @ 2024-05-15 585/week @ 2024-05-22 679/week @ 2024-05-29 586/week @ 2024-06-05 906/week @ 2024-06-12 666/week @ 2024-06-19 605/week @ 2024-06-26 477/week @ 2024-07-03 452/week @ 2024-07-10 463/week @ 2024-07-17 513/week @ 2024-07-24 966/week @ 2024-07-31 951/week @ 2024-08-07 608/week @ 2024-08-14

3,143 每月下载量
3 个仓中使用 (直接使用 2 个)

MIT/ApacheGPL-3.0-or-later

90KB
2K SLoC

锰元素 CLI 支持

此仓提供与锰元素宏集成的实用工具,使得将资产收集和优化系统集成到构建工具中变得容易。

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

依赖关系

~73MB
~1.5M SLoC