33 lines
987 B
Rust
33 lines
987 B
Rust
use std::error::Error;
|
|
use std::fs::{self, File};
|
|
use std::io::Write;
|
|
use std::path::Path;
|
|
|
|
use lightningcss::bundler::{Bundler, FileProvider};
|
|
use lightningcss::printer::PrinterOptions;
|
|
use lightningcss::stylesheet::{MinifyOptions, ParserOptions};
|
|
|
|
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()
|
|
});
|
|
|
|
let mut output_file = File::create(output_path)?;
|
|
output_file.write_all(minified_css.unwrap().code.as_bytes())?;
|
|
|
|
Ok(())
|
|
}
|