Skip to content

Commit 8b55853

Browse files
committed
refactor(build): use lightningcss instead of css-minify
1 parent 79be58d commit 8b55853

File tree

3 files changed

+14
-70
lines changed

3 files changed

+14
-70
lines changed

Cargo.lock

+3-57
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ walkdir = "2.5.0"
3939
minify-html = "0.15.0"
4040
num_cpus = "1.16.0"
4141
minify-js = "0.6.0"
42-
css-minify = "0.5.2"
4342
regex = "1.11.1"
4443
semver = { version = "1.0.25", features = ["serde"] }
4544
git2 = "0.20.0"
@@ -53,6 +52,7 @@ colored = "3.0.0"
5352
local-ip-address = "0.6.3"
5453
titlecase = "3.3.0"
5554
rss = "2.0.12"
55+
lightningcss = "1.0.0-alpha.64"
5656

5757
[dev-dependencies]
5858
mockall = "0.13.1"

src/cmd/build.rs

+10-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ use std::{
66
use colored::Colorize;
77
use eyre::{bail, eyre, Result, WrapErr};
88
use futures_util::{self, StreamExt};
9+
use lightningcss::stylesheet::{
10+
StyleSheet, ParserOptions, MinifyOptions, PrinterOptions
11+
};
912
use rss::Channel;
1013
use tera::{Context, Tera};
1114
use tokio::sync::Mutex;
@@ -444,18 +447,13 @@ async fn minify_js_asset(src_path: &Path, dest_path: &Path) -> Result<()> {
444447
/// * `Result<()>` - `Ok(())` if minification and writing succeed, otherwise an error.
445448
#[instrument(skip(src_path, dest_path))]
446449
async fn minify_css_asset(src_path: &Path, dest_path: &Path) -> Result<()> {
447-
let content = tokio::fs::read_to_string(src_path).await?;
448-
// See https://docs.rs/css-minify/0.5.2/css_minify/optimizations/enum.Level.html#variants
449-
let minified = css_minify::optimizations::Minifier::default()
450-
.minify(&content, css_minify::optimizations::Level::Two)
451-
.map_err(|e| {
452-
eyre!(
453-
"{}: {}",
454-
format!("CSS minification failed for {}", src_path.display()).bold(),
455-
e
456-
)
457-
})?;
458-
tokio::fs::write(dest_path, minified.into_bytes())
450+
let content = tokio::fs::read_to_string(src_path).await?.leak();
451+
452+
let mut stylesheet = StyleSheet::parse(content, ParserOptions::default())?;
453+
stylesheet.minify(MinifyOptions::default())?;
454+
let minified = stylesheet.to_css(PrinterOptions { minify: true, ..Default::default() })?;
455+
456+
tokio::fs::write(dest_path, minified.code)
459457
.await
460458
.wrap_err_with(|| {
461459
format!("Failed to write minified CSS to {}", dest_path.display()).bold()

0 commit comments

Comments
 (0)