This repository has been archived on 2024-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
clego-app/build.rs

33 lines
987 B
Rust
Raw Normal View History

use std::error::Error;
use std::fs::{self, File};
use std::io::Write;
use std::path::Path;
use lightningcss::bundler::{Bundler, FileProvider};
2024-04-27 13:24:23 +02:00
use lightningcss::printer::PrinterOptions;
use lightningcss::stylesheet::{MinifyOptions, ParserOptions};
2024-04-27 20:11:28 +02:00
fn main() -> Result<(), Box<dyn Error>> {
let input_path = Path::new("styles/global.css");
let output_path = Path::new("public/styles/global.css");
if let Some(parent) = output_path.parent() {
fs::create_dir_all(parent)?;
}
let fs = FileProvider::new();
let mut bundler = Bundler::new(&fs, None, ParserOptions::default());
let mut stylesheet = bundler.bundle(input_path).unwrap();
let _ = stylesheet.minify(MinifyOptions::default());
let minified_css = stylesheet.to_css(PrinterOptions {
minify: true,
..PrinterOptions::default()
});
2024-04-27 13:24:23 +02:00
let mut output_file = File::create(output_path)?;
output_file.write_all(minified_css.unwrap().code.as_bytes())?;
Ok(())
}