hyperbuild 0.1.7 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +37 -24
- data/lib/linux-ruby2.5 +0 -0
- data/lib/linux-ruby2.6 +0 -0
- data/lib/linux-ruby2.7 +0 -0
- data/lib/macos-ruby2.5 +0 -0
- data/lib/macos-ruby2.6 +0 -0
- data/lib/macos-ruby2.7 +0 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d7fbd72c38ff0d0538916b9ff6e00a84adf12124666dd14d7813d7afe128242
|
4
|
+
data.tar.gz: 61e2dbc5bb2f90f2d7d09e85e8763ccf2394d40a2bc68273c7b9d2eccbc13c17
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c880cc9b43f1267b413b7966c7c372f3837c68f236b2051df048b848de4f04ef55a89e18de02a9d5c4178dee6c42e2a12d9e14be1f22fad032d2aeea7b3edd84
|
7
|
+
data.tar.gz: 8e42e3e6ba37452d39fcc516bfa6705f876eb4550dafe01cd1cebc3448b3fe0bae11fbd8c81358af8c0e40f091cc72d7bb81358770fe2fdf5ab67ea82f1c0cba
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
A fast one-pass in-place HTML minifier written in Rust with context-aware whitespace handling.
|
4
4
|
|
5
|
+
Also supports JS minification by plugging into [esbuild](https://github.com/evanw/esbuild).
|
6
|
+
|
5
7
|
Available as:
|
6
8
|
- CLI for Windows, macOS, and Linux.
|
7
9
|
- Rust library.
|
@@ -12,12 +14,13 @@ Available as:
|
|
12
14
|
- Minification is done in one pass with no backtracking or DOM/AST building.
|
13
15
|
- No extra heap memory is allocated during processing, which increases performance.
|
14
16
|
- Context-aware whitespace handling allows maximum minification while retaining desired spaces.
|
17
|
+
- Well tested with a large test suite and extensive [fuzzing](./fuzz).
|
15
18
|
|
16
19
|
## Performance
|
17
20
|
|
18
21
|
Speed and effectiveness of Node.js version compared to [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize), run on popular already-minified web pages. See [bench](./bench) folder for more details.
|
19
22
|
|
20
|
-
<img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.
|
23
|
+
<img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.2.2/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.2.2/average-sizes.png">
|
21
24
|
|
22
25
|
## Usage
|
23
26
|
|
@@ -25,14 +28,18 @@ Speed and effectiveness of Node.js version compared to [html-minfier](https://gi
|
|
25
28
|
|
26
29
|
Precompiled binaries are available for x86-64 Windows, macOS, and Linux.
|
27
30
|
|
31
|
+
Building from source currently requires the Go compiler to be installed as well, to build the [JS minifier](https://github.com/evanw/esbuild).
|
32
|
+
|
28
33
|
##### Get
|
29
34
|
|
30
|
-
[Windows](https://wilsonl.in/hyperbuild/bin/0.
|
31
|
-
[macOS](https://wilsonl.in/hyperbuild/bin/0.
|
32
|
-
[Linux](https://wilsonl.in/hyperbuild/bin/0.
|
35
|
+
[Windows](https://wilsonl.in/hyperbuild/bin/0.2.2-windows-x86_64.exe) |
|
36
|
+
[macOS](https://wilsonl.in/hyperbuild/bin/0.2.2-macos-x86_64) |
|
37
|
+
[Linux](https://wilsonl.in/hyperbuild/bin/0.2.2-linux-x86_64)
|
33
38
|
|
34
39
|
##### Use
|
35
40
|
|
41
|
+
Use the `--help` argument for more details.
|
42
|
+
|
36
43
|
```bash
|
37
44
|
hyperbuild --src /path/to/src.html --out /path/to/output.min.html
|
38
45
|
```
|
@@ -46,34 +53,37 @@ hyperbuild --src /path/to/src.html --out /path/to/output.min.html
|
|
46
53
|
|
47
54
|
```toml
|
48
55
|
[dependencies]
|
49
|
-
hyperbuild = "0.
|
56
|
+
hyperbuild = "0.2.2"
|
50
57
|
```
|
51
58
|
|
52
59
|
##### Use
|
53
60
|
|
54
61
|
```rust
|
55
|
-
use hyperbuild::{FriendlyError, hyperbuild};
|
62
|
+
use hyperbuild::{Cfg, FriendlyError, hyperbuild, hyperbuild_copy, hyperbuild_friendly_error, hyperbuild_truncate};
|
56
63
|
|
57
64
|
fn main() {
|
58
65
|
let mut code = b"<p> Hello, world! </p>".to_vec();
|
66
|
+
let cfg = &Cfg {
|
67
|
+
minify_js: false,
|
68
|
+
};
|
59
69
|
|
60
70
|
// Minifies a slice in-place and returns the new minified length,
|
61
71
|
// but leaves any original code after the minified code intact.
|
62
|
-
match hyperbuild(&mut code) {
|
72
|
+
match hyperbuild(&mut code, cfg) {
|
63
73
|
Ok(minified_len) => {}
|
64
74
|
Err((error_type, error_position)) => {}
|
65
75
|
};
|
66
76
|
|
67
77
|
// Creates a vector copy containing only minified code
|
68
78
|
// instead of minifying in-place.
|
69
|
-
match hyperbuild_copy(&code) {
|
79
|
+
match hyperbuild_copy(&code, cfg) {
|
70
80
|
Ok(minified) => {}
|
71
81
|
Err((error_type, error_position)) => {}
|
72
82
|
};
|
73
83
|
|
74
84
|
// Minifies a vector in-place, and then truncates the
|
75
85
|
// vector to the new minified length.
|
76
|
-
match hyperbuild_truncate(&mut code) {
|
86
|
+
match hyperbuild_truncate(&mut code, cfg) {
|
77
87
|
Ok(()) => {}
|
78
88
|
Err((error_type, error_position)) => {}
|
79
89
|
};
|
@@ -81,7 +91,7 @@ fn main() {
|
|
81
91
|
// Identical to `hyperbuild` except with FriendlyError instead.
|
82
92
|
// `code_context` is a string of a visual representation of the source,
|
83
93
|
// with line numbers and position markers to aid in debugging syntax.
|
84
|
-
match hyperbuild_friendly_error(&mut code) {
|
94
|
+
match hyperbuild_friendly_error(&mut code, cfg) {
|
85
95
|
Ok(minified_len) => {}
|
86
96
|
Err(FriendlyError { position, message, code_context }) => {
|
87
97
|
eprintln!("Failed at character {}:", position);
|
@@ -118,10 +128,11 @@ yarn add hyperbuild
|
|
118
128
|
```js
|
119
129
|
const hyperbuild = require("hyperbuild");
|
120
130
|
|
121
|
-
const
|
131
|
+
const cfg = { minifyJs: false };
|
132
|
+
const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
122
133
|
|
123
134
|
// Alternatively, minify in place to avoid copying.
|
124
|
-
const source = Buffer.from("<p> Hello, world! </p>");
|
135
|
+
const source = Buffer.from("<p> Hello, world! </p>", cfg);
|
125
136
|
hyperbuild.minifyInPlace(source);
|
126
137
|
```
|
127
138
|
|
@@ -131,8 +142,9 @@ hyperbuild is also available for TypeScript:
|
|
131
142
|
import * as hyperbuild from "hyperbuild";
|
132
143
|
import * as fs from "fs";
|
133
144
|
|
134
|
-
const
|
135
|
-
hyperbuild.
|
145
|
+
const cfg = { minifyJs: false };
|
146
|
+
const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
147
|
+
hyperbuild.minifyInPlace(fs.readFileSync("source.html"), cfg);
|
136
148
|
```
|
137
149
|
|
138
150
|
</details>
|
@@ -150,7 +162,7 @@ Add as a Maven dependency:
|
|
150
162
|
<dependency>
|
151
163
|
<groupId>in.wilsonl.hyperbuild</groupId>
|
152
164
|
<artifactId>hyperbuild</artifactId>
|
153
|
-
<version>0.
|
165
|
+
<version>0.2.2</version>
|
154
166
|
</dependency>
|
155
167
|
```
|
156
168
|
|
@@ -159,15 +171,18 @@ Add as a Maven dependency:
|
|
159
171
|
```java
|
160
172
|
import in.wilsonl.hyperbuild.Hyperbuild;
|
161
173
|
|
174
|
+
Hyperbuild.Configuration cfg = new Hyperbuild.Configuration.Builder()
|
175
|
+
.setMinifyJs(false)
|
176
|
+
.build();
|
162
177
|
try {
|
163
|
-
String minified = Hyperbuild.minify("<p> Hello, world! </p>");
|
178
|
+
String minified = Hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
164
179
|
} catch (Hyperbuild.SyntaxException e) {
|
165
180
|
System.err.println(e.getMessage());
|
166
181
|
}
|
167
182
|
|
168
183
|
// Alternatively, minify in place:
|
169
184
|
assert source instanceof ByteBuffer && source.isDirect();
|
170
|
-
Hyperbuild.minifyInPlace(source);
|
185
|
+
Hyperbuild.minifyInPlace(source, cfg);
|
171
186
|
```
|
172
187
|
|
173
188
|
</details>
|
@@ -187,7 +202,7 @@ Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
|
|
187
202
|
import hyperbuild
|
188
203
|
|
189
204
|
try:
|
190
|
-
minified = hyperbuild.minify("<p> Hello, world! </p>")
|
205
|
+
minified = hyperbuild.minify("<p> Hello, world! </p>", minify_js=False)
|
191
206
|
except SyntaxError as e:
|
192
207
|
print(e)
|
193
208
|
```
|
@@ -208,17 +223,13 @@ Add the library as a dependency to `Gemfile` or `*.gemspec`.
|
|
208
223
|
```ruby
|
209
224
|
require 'hyperbuild'
|
210
225
|
|
211
|
-
print Hyperbuild.minify
|
226
|
+
print Hyperbuild.minify("<p> Hello, world! </p>", { :minify_js => false })
|
212
227
|
```
|
213
228
|
|
214
229
|
</details>
|
215
230
|
|
216
231
|
## Minification
|
217
232
|
|
218
|
-
### Configurability
|
219
|
-
|
220
|
-
Configuration of minification is currently WIP across all languages. The behaviour mentioned below is the default.
|
221
|
-
|
222
233
|
### Whitespace
|
223
234
|
|
224
235
|
hyperbuild has advanced context-aware whitespace minification that does things such as:
|
@@ -440,6 +451,8 @@ Numeric entities that do not refer to a valid [Unicode Scalar Value](https://www
|
|
440
451
|
|
441
452
|
If an entity is unintentionally formed after decoding, the leading ampersand is encoded, e.g. `&amp;` becomes `&amp;`. This is done as `&` is equal to or shorter than all other entity representations of characters part of an entity (`[&#a-zA-Z0-9;]`), and there is no other conflicting entity name that starts with `amp`.
|
442
453
|
|
454
|
+
It's possible to get an unintentional entity after removing comments, e.g. `&am<!-- -->p`.
|
455
|
+
|
443
456
|
Left chevrons after any decoding in text are encoded to `<` if possible or `<` otherwise.
|
444
457
|
|
445
458
|
### Comments
|
@@ -454,7 +467,7 @@ Bangs, [processing instructions](https://en.wikipedia.org/wiki/Processing_Instru
|
|
454
467
|
|
455
468
|
Only UTF-8/ASCII-encoded HTML code is supported.
|
456
469
|
|
457
|
-
hyperbuild
|
470
|
+
hyperbuild does no syntax checking or standards enforcement for performance and code complexity reasons.
|
458
471
|
|
459
472
|
For example, this means that it's not an error to have self-closing tags, declare multiple `<body>` elements, use incorrect attribute names and values, or write something like `<br>alert('');</br>`
|
460
473
|
|
data/lib/linux-ruby2.5
CHANGED
Binary file
|
data/lib/linux-ruby2.6
CHANGED
Binary file
|
data/lib/linux-ruby2.7
CHANGED
Binary file
|
data/lib/macos-ruby2.5
CHANGED
Binary file
|
data/lib/macos-ruby2.6
CHANGED
Binary file
|
data/lib/macos-ruby2.7
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyperbuild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Lin
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: fiddle
|
@@ -62,6 +62,5 @@ rubyforge_project:
|
|
62
62
|
rubygems_version: 2.7.6.2
|
63
63
|
signing_key:
|
64
64
|
specification_version: 4
|
65
|
-
summary: Fast
|
66
|
-
handling
|
65
|
+
summary: Fast allocation-less HTML minifier with smart whitespace handling
|
67
66
|
test_files: []
|