Files
2026-07-13 12:25:07 +08:00

42 lines
2.9 KiB
Rust

// ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
// ┃ ██████ ██████ ██████ █ █ █ █ █ █▄ ▀███ █ ┃
// ┃ ▄▄▄▄▄█ █▄▄▄▄▄ ▄▄▄▄▄█ ▀▀▀▀▀█▀▀▀▀▀ █ ▀▀▀▀▀█ ████████▌▐███ ███▄ ▀█ █ ▀▀▀▀▀ ┃
// ┃ █▀▀▀▀▀ █▀▀▀▀▀ █▀██▀▀ ▄▄▄▄▄ █ ▄▄▄▄▄█ ▄▄▄▄▄█ ████████▌▐███ █████▄ █ ▄▄▄▄▄ ┃
// ┃ █ ██████ █ ▀█▄ █ ██████ █ ███▌▐███ ███████▄ █ ┃
// ┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫
// ┃ Copyright (c) 2017, the Perspective Authors. ┃
// ┃ ╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ┃
// ┃ This file is part of the Perspective library, distributed under the terms ┃
// ┃ of the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0). ┃
// ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
use glob::glob;
use lightningcss::bundler::{Bundler, FileProvider};
use lightningcss::stylesheet::PrinterOptions;
fn main() -> Result<(), anyhow::Error> {
let out_dir = std::env::var("OUT_DIR").unwrap();
let out_path = std::path::Path::new(&out_dir);
let fs: &'static FileProvider = Box::leak(Box::new(FileProvider::new()));
for entry in glob("./src/css/**/*.css")? {
let entry = entry?;
let relative = entry
.strip_prefix("./src/css/")
.or_else(|_| entry.strip_prefix("src/css/"))?;
let mut bundler = Bundler::new(fs, None, Default::default());
let stylesheet = bundler.bundle(&entry)?;
let output = stylesheet.to_css(PrinterOptions {
minify: true,
..Default::default()
})?;
let out_file = out_path.join("css").join(relative);
std::fs::create_dir_all(out_file.parent().unwrap())?;
std::fs::write(&out_file, output.code)?;
println!("cargo:rerun-if-changed={}", entry.display());
}
Ok(())
}