From f6f6b4c20cab63fdc90998501479fa072756371f Mon Sep 17 00:00:00 2001 From: Charly Lersteau <645647+charlyisidore@users.noreply.github.com> Date: Sat, 9 Aug 2025 07:44:43 +0800 Subject: [PATCH] Add lightningcss and minify-js feature flags --- bench/runners/minify-html/Cargo.toml | 5 +++++ bench/runners/minify-html/src/main.rs | 10 ++++++++-- minify-html/Cargo.toml | 9 +++++++-- minify-html/src/cfg/mod.rs | 2 ++ minify-html/src/minify/attr.rs | 10 ++++------ minify-html/src/minify/content.rs | 8 +++++++- minify-html/src/minify/mod.rs | 2 ++ minify-html/src/tests/mod.rs | 8 ++++++++ 8 files changed, 43 insertions(+), 11 deletions(-) diff --git a/bench/runners/minify-html/Cargo.toml b/bench/runners/minify-html/Cargo.toml index 5038b337..65c15247 100644 --- a/bench/runners/minify-html/Cargo.toml +++ b/bench/runners/minify-html/Cargo.toml @@ -9,3 +9,8 @@ edition = "2018" minify-html = { path = "../../../minify-html" } serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.44" + +[features] +default = ["lightningcss", "minify-js"] +lightningcss = ["minify-html/lightningcss"] +minify-js = ["minify-html/minify-js"] diff --git a/bench/runners/minify-html/src/main.rs b/bench/runners/minify-html/src/main.rs index 59c737e7..8e15f424 100644 --- a/bench/runners/minify-html/src/main.rs +++ b/bench/runners/minify-html/src/main.rs @@ -21,8 +21,14 @@ fn main() { let mut cfg = Cfg::new(); cfg.enable_possibly_noncompliant(); if !html_only { - cfg.minify_css = true; - cfg.minify_js = true; + #[cfg(feature = "lightningcss")] + { + cfg.minify_css = true; + } + #[cfg(feature = "minify-js")] + { + cfg.minify_js = true; + } }; for t in fs::read_dir(input_dir).unwrap().map(|d| d.unwrap()) { diff --git a/minify-html/Cargo.toml b/minify-html/Cargo.toml index baa912aa..33e27b46 100644 --- a/minify-html/Cargo.toml +++ b/minify-html/Cargo.toml @@ -17,8 +17,13 @@ maintenance = { status = "actively-developed" } [dependencies] ahash = "0.8" aho-corasick = "0.7" -lightningcss = "1.0.0-alpha.65" +lightningcss = { version = "1.0.0-alpha.65", optional = true } memchr = "2" minify-html-common = { version = "0.0.2", path = "../minify-html-common" } -minify-js = "0.6" +minify-js = { version = "0.6", optional = true } once_cell = "1.19.0" + +[features] +default = ["lightningcss", "minify-js"] +lightningcss = ["dep:lightningcss"] +minify-js = ["dep:minify-js"] diff --git a/minify-html/src/cfg/mod.rs b/minify-html/src/cfg/mod.rs index 1fd63be7..ffc68b3b 100644 --- a/minify-html/src/cfg/mod.rs +++ b/minify-html/src/cfg/mod.rs @@ -18,10 +18,12 @@ pub struct Cfg { pub keep_input_type_text_attr: bool, /// Keep SSI comments. pub keep_ssi_comments: bool, + #[cfg(feature = "lightningcss")] /// Minify CSS in `