From c7d0652fbcf4a961063baaf21f22841808cfe526 Mon Sep 17 00:00:00 2001 From: Wilson Lin Date: Tue, 21 Jun 2022 17:29:12 +1000 Subject: [PATCH] Use minify-js as JS minifier --- README.md | 14 ++++---- bench/runners/minify-html/Cargo.toml | 2 +- cli/Cargo.toml | 2 +- java/Cargo.toml | 2 +- nodejs/index.d.ts | 4 +-- nodejs/native/Cargo.toml | 6 +--- python/Cargo.js.toml | 2 +- ruby/Cargo.toml | 2 +- rust/common/tests/mod.rs | 40 +++++++++-------------- rust/main/Cargo.toml | 8 ++--- rust/main/src/cfg/mod.rs | 7 ++-- rust/main/src/minify/attr.rs | 44 ++++++++++++------------- rust/main/src/minify/css.rs | 48 ++++++++-------------------- rust/main/src/minify/esbuild.rs | 18 ----------- rust/main/src/minify/js.rs | 46 ++++++++------------------ rust/main/src/minify/mod.rs | 1 - rust/main/src/tests/mod.rs | 5 +-- version | 2 +- 18 files changed, 82 insertions(+), 171 deletions(-) delete mode 100644 rust/main/src/minify/esbuild.rs diff --git a/README.md b/README.md index 5987d24..081d5f6 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ A Rust HTML minifier meticulously optimised for speed and effectiveness, with bi - Advanced minification strategy beats other minifiers while being much faster. - Uses SIMD searching, direct tries, and lookup tables. - Handles [invalid HTML](./notes/Parsing.md), with extensive testing and [fuzzing](./fuzz). -- Natively binds to [esbuild](https://github.com/wilsonzlin/esbuild-rs) for super fast JS and CSS minification. +- Uses [minify-js](https://github.com/wilsonzlin/minify-js) for super fast JS minification. ## Performance @@ -55,13 +55,9 @@ minify-html --output /path/to/output.min.html --keep-closing-tags --minify-css / ```toml [dependencies] -minify-html = { version = "0.8.1", features = ["js-esbuild"] } +minify-html = { version = "0.8.1" } ``` -Building with the `js-esbuild` feature requires the Go compiler to be installed as well, to build the [JS and CSS minifier](https://github.com/wilsonzlin/esbuild-rs). - -If the `js-esbuild` feature is not enabled, `cfg.minify_js` and `cfg.minify_css` will have no effect. - ### Use Check out the [docs](https://docs.rs/minify-html) for API and usage examples. @@ -190,7 +186,11 @@ All [`Cfg` fields](https://docs.rs/minify-html/latest/minify_html/struct.Cfg.htm ## Minification -Note that some of the minification done can result in HTML that will not pass validation, but remain interpreted and rendered correctly by the browser; essentially, the laxness of the browser is taken advantage of for better minification. These can be turned off via the `Cfg` object. +Note that some of the minification done can result in HTML that will not pass validation, but remain interpreted and rendered correctly by the browser; essentially, the laxness of the browser is taken advantage of for better minification. To prevent this, refer to these configuration options: + +- `do_not_minify_doctype` +- `ensure_spec_compliant_unquoted_attribute_values` +- `keep_spaces_between_attributes` ### Whitespace diff --git a/bench/runners/minify-html/Cargo.toml b/bench/runners/minify-html/Cargo.toml index 65a09f7..970ba53 100644 --- a/bench/runners/minify-html/Cargo.toml +++ b/bench/runners/minify-html/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Wilson Lin "] edition = "2018" [dependencies] -minify-html = { path = "../../../rust/main", features = ["js-esbuild"] } +minify-html = { path = "../../../rust/main" } serde = { version = "1.0.104", features = ["derive"] } serde_json = "1.0.44" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 74e9277..6fdef4f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -7,5 +7,5 @@ authors = ["Wilson Lin "] edition = "2018" [dependencies] -minify-html = { path = "../rust/main", features = ["js-esbuild"] } +minify-html = { path = "../rust/main" } structopt = "0.3" diff --git a/java/Cargo.toml b/java/Cargo.toml index 1ba6160..e2f1bcb 100644 --- a/java/Cargo.toml +++ b/java/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Wilson Lin "] edition = "2018" [dependencies] -minify-html = { path = "../rust/main", features = ["js-esbuild"] } +minify-html = { path = "../rust/main" } jni = "0.14.0" [lib] diff --git a/nodejs/index.d.ts b/nodejs/index.d.ts index 73d1dce..fc5c93a 100644 --- a/nodejs/index.d.ts +++ b/nodejs/index.d.ts @@ -21,11 +21,11 @@ export function createConfiguration (options: { /** Keep all comments. */ keep_comments?: boolean; /** - * If enabled, content in `", b""); + eval_with_js_min(b"", b""); eval_with_js_min( b"", - b"", - ); - // `export` statements are not allowed inline. - eval_with_js_min( - b"", - b"", + b"", ); eval_with_js_min( br#" "#, - b"", + b"", ); eval_with_js_min( b"", @@ -491,39 +483,37 @@ fn test_js_minification() { let a = 1; "#, - b"", + b"", ); } -#[cfg(feature = "js-esbuild")] +/* TODO Reenable once unintentional script closing tag escaping is implemented in minify-js. #[test] fn test_js_minification_unintentional_closing_tag() { eval_with_js_min( br#""#, br#""#, ); - // TODO Reenable once esbuild handles closing tags case insensitively (evanw/esbuild#1509). - // eval_with_js_min( - // br#""#, - // br#""#, - // ); + eval_with_js_min( + br#""#, + br#""#, + ); eval_with_js_min( br#""#, br#""#, ); - // TODO Reenable once esbuild handles closing tags case insensitively (evanw/esbuild#1509). - // eval_with_js_min( - // br#""#, - // br#""#, - // ); + eval_with_js_min( + br#""#, + br#""#, + ); } +*/ -#[cfg(feature = "js-esbuild")] #[test] fn test_style_element_minification() { // `", - b"", + b"", ); } diff --git a/rust/main/Cargo.toml b/rust/main/Cargo.toml index 1ad7a6c..ab1fa6c 100644 --- a/rust/main/Cargo.toml +++ b/rust/main/Cargo.toml @@ -15,13 +15,9 @@ include = ["/src/**/*", "/Cargo.toml", "/LICENSE", "/README.md"] [badges] maintenance = { status = "actively-developed" } -[features] -default = [] -js-esbuild = ["crossbeam", "esbuild-rs"] - [dependencies] aho-corasick = "0.7" -crossbeam = { version = "0.7", optional = true } -esbuild-rs = { version = "0.13.8", optional = true } +css-minify = "0.2.2" +minify-js = "0.1.0" lazy_static = "1.4" memchr = "2" diff --git a/rust/main/src/cfg/mod.rs b/rust/main/src/cfg/mod.rs index 72d1b27..4743ebd 100644 --- a/rust/main/src/cfg/mod.rs +++ b/rust/main/src/cfg/mod.rs @@ -14,13 +14,10 @@ pub struct Cfg { pub keep_spaces_between_attributes: bool, /// Keep all comments. pub keep_comments: bool, - /// If enabled, CSS in `