Repository navigation
Make JS (oxc) and CSS (lightningcss) minification opt-in via js/css features - #289
Open
FalkWoldmann wants to merge 2 commits into
Open
FalkWoldmann wants to merge 2 commits into
FalkWoldmann wants to merge 2 commits into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We use
minify-htmlpurely for HTML whitespace/attribute minification (Cfg::minify_jsandCfg::minify_cssare both leftfalse). Auditing our dependency tree showed thatminify-htmlalone pulls in 62 crates exclusively — the full oxc toolchain (oxc_allocator,oxc_codegen,oxc_minifier,oxc_parser,oxc_span, plus their own transitive deps) andlightningcss(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 andstyle-attribute minifierConsumers that only need HTML minification can now opt out of both with
default-features = falseand drop ~55 transitive crates from their build.Implementation
js.rs/css.rs: the existingif cfg.minify_js { ... }/if cfg.minify_css { ... }bodies are extracted into a private helper (minify_js_with_oxc/minify_css_with_lightningcss) returningbool(whether a smaller minified result was produced). The feature-gated version is unchanged logic; a#[cfg(not(feature = ...))]twin always returnsfalse, so the publicminify_js/minify_cssfunctions and their fallback-to-trimmed behavior are identical either way.attr.rs: the inlinestyle-attribute minification block is extracted the same way intominify_style_attr_value, gated on thecssfeature.Cfg::minify_js/Cfg::minify_cssbehave asfalsewhen 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; theCfgstruct and its fields are untouched.--no-default-featuresand runningcfg.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
js+cssboth 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.