1 个不稳定版本
0.0.1 | 2024年7月1日 |
---|
#296 in #assets
15KB
122 代码行
Manganis
Manganis 允许您将资产提交到支持收集资产的构建工具。它使您能够轻松地自托管分布在您库中的资产。Manganis 还处理优化、转换和获取资产。
如果您在组件库中定义了此内容
const AVIF_ASSET: &str = manganis::mg!(file("rustacean-flat-gesture.png"));
AVIF_ASSET 将被设置为一些 CLI 将提供的新文件名。该文件可以被任何依赖组件库的包收集。
// 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!(file("test-package-dependency/src/asset.txt"));
// You can use URLs to copy read the asset at build time
const _: &str = manganis::mg!(file("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"));
为您的 CLI 添加支持
要为您的 CLI 添加支持,您需要与 manganis_cli_support crate 集成。此 crate 提供了与 Manganis 宏集成的实用工具,以收集资产。它使得将资产收集和优化系统集成到构建工具中变得简单。
依赖关系
~5–23MB
~367K SLoC