8000 Make JS (oxc) and CSS (lightningcss) minification opt-in via `js`/`css` features by FalkWoldmann · Pull Request #289 · wilsonzlin/minify-html · GitHub
[go: up one dir, main page]

Skip to content

Make JS (oxc) and CSS (lightningcss) minification opt-in via js/css features - #289

Open
FalkWoldmann wants to merge 2 commits into
wilsonzlin:masterfrom
FalkWoldmann:feature/js-css-optional-features
Open

FalkWoldmann wants to merge 2 commits into
wilsonzlin:masterfrom
FalkWoldmann:feature/js-css-optional-features

Conversation

@FalkWoldmann
Copy link
Copy Markdown

Motivation

We use minify-html purely for HTML whitespace/attribute minification (Cfg::minify_js and Cfg::minify_css are both left false). Auditing our dependency tree showed that minify-html alone pulls in 62 crates exclusively — the full oxc toolchain (oxc_allocator, oxc_codegen, oxc_minifier, oxc_parser, oxc_span, plus their own transitive deps) and lightningcss (currently pinned at a pre-1.0 alpha) — none of which are ever exercised at runtime for us, since both minification paths are gated behind config flags we never enable.

What this does

Adds two Cargo features, both on by default so existing consumers are unaffected:

  • js — gates the oxc-based <script> minifier (oxc_allocator, oxc_codegen, oxc_minifier, oxc_parser, oxc_span)
  • css — gates the lightningcss-based <style>-tag and style-attribute minifier

Consumers that only need HTML minification can now opt out of both with default-features = false and drop ~55 transitive crates from their build.

Implementation

  • js.rs / css.rs: the existing if cfg.minify_js { ... } / if cfg.minify_css { ... } bodies are extracted into a private helper (minify_js_with_oxc / minify_css_with_lightningcss) returning bool (whether a smaller minified result was produced). The feature-gated version is unchanged logic; a #[cfg(not(feature = ...))] twin always returns false, so the public minify_js/minify_css functions and their fallback-to-trimmed behavior are identical either way.
  • attr.rs: the inline style-attribute minification block is extracted the same way into minify_style_attr_value, gated on the css feature.
  • Cfg::minify_js / Cfg::minify_css behave as false when the corresponding feature is disabled, regardless of what the caller sets — i.e. disabling the feature is equivalent to the flag never being enabled. No public API changes; the Cfg struct and its fields are untouched.
  • No test changes: existing tests use default features (both on) and are unaffected. Building with --no-default-features and running cfg.minify_js/cfg.minify_css-exercising tests would fail as expected (the feature is off), which is the intended, self-consistent behavior for an opt-out feature.

Compatibility

  • Default feature set is unchanged (js + css both on), so this is not a breaking change for any existing consumer, including the other bindings in this repo (Node.js, Python, Ruby, Java, WASM, CLI) which all depend on the crate with default features.
  • Happy to adjust the feature names/granularity, or split into two PRs, if you'd prefer.

…s` features

Both are enabled by default, so existing consumers see no change.
Consumers that only need HTML/whitespace minification (`Cfg::minify_js`
and `Cfg::minify_css` both false) can now build with
`default-features = false` to drop the oxc_* crates (JS parser/minifier)
and lightningcss (CSS parser/minifier) from their dependency graph.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0