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
953 B
Rust
Raw Normal View History

use std::error::Error;
use std::fs::{self, File};
use std::io::Write;
use std::path::Path;
2024-04-27 13:24:23 +02:00
use lightningcss::printer::PrinterOptions;
2024-04-30 16:23:04 +02:00
use lightningcss::stylesheet::{ParserOptions, StyleSheet};
2024-04-27 20:11:28 +02:00
fn main() -> Result<(), Box<dyn Error>> {
let scss_path = Path::new("styles/global.scss");
let css_output_path = Path::new("public/styles/global.css");
if let Some(parent) = css_output_path.parent() {
fs::create_dir_all(parent)?;
}
let css = grass::from_path(scss_path, &grass::Options::default())
.map_err(|e| Box::new(e) as Box<dyn Error>)?;
2024-04-27 13:24:23 +02:00
let stylesheet = StyleSheet::parse(&css, ParserOptions::default()).unwrap();
2024-04-30 16:23:04 +02:00
let minified_css = stylesheet
.to_css(PrinterOptions {
minify: true,
..PrinterOptions::default()
})
.unwrap();
2024-04-27 13:24:23 +02:00
let mut output_file = File::create(css_output_path)?;
2024-04-27 13:24:23 +02:00
output_file.write_all(minified_css.code.as_bytes())?;
Ok(())
}