hyperbuild 0.1.10 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +40 -26
- 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: e83b0423aee5805c928eaea74b59e6b230bd5445b96bc7d01de4de3d851c6651
|
4
|
+
data.tar.gz: e095ae3c16b327a8712a0ff049f4908ddf7ce3292a128f516933c00c2d455d8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9adcacde88b2985ae0488ea1555c6c83ac376492cd21c2316fa3130176ccce17c11c75f2d7ed30f94c03bd1454bc117221dc63523e45c69d305aa2fb562803f
|
7
|
+
data.tar.gz: d19a164fc4709d8448408f54d417d62df4bd5bcf7eda5d90296c987c350ce1611dec530a23dffc6915bf19f63550bbd88e6bea73df8446b079f43382ff27338f
|
data/README.md
CHANGED
@@ -2,8 +2,10 @@
|
|
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
|
-
- CLI for
|
8
|
+
- CLI for macOS and Linux.
|
7
9
|
- Rust library.
|
8
10
|
- Native library for Node.js, Python, Java, and Ruby.
|
9
11
|
|
@@ -12,27 +14,29 @@ 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.4/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.2.4/average-sizes.png">
|
21
24
|
|
22
25
|
## Usage
|
23
26
|
|
24
27
|
### CLI
|
25
28
|
|
26
|
-
Precompiled binaries are available for x86-64
|
29
|
+
Precompiled binaries are available for x86-64 macOS and Linux.
|
27
30
|
|
28
31
|
##### Get
|
29
32
|
|
30
|
-
[
|
31
|
-
[
|
32
|
-
[Linux](https://wilsonl.in/hyperbuild/bin/0.1.10-linux-x86_64)
|
33
|
+
[macOS](https://wilsonl.in/hyperbuild/bin/0.2.4-macos-x86_64) |
|
34
|
+
[Linux](https://wilsonl.in/hyperbuild/bin/0.2.4-linux-x86_64)
|
33
35
|
|
34
36
|
##### Use
|
35
37
|
|
38
|
+
Use the `--help` argument for more details.
|
39
|
+
|
36
40
|
```bash
|
37
41
|
hyperbuild --src /path/to/src.html --out /path/to/output.min.html
|
38
42
|
```
|
@@ -46,34 +50,41 @@ hyperbuild --src /path/to/src.html --out /path/to/output.min.html
|
|
46
50
|
|
47
51
|
```toml
|
48
52
|
[dependencies]
|
49
|
-
hyperbuild = "0.
|
53
|
+
hyperbuild = { version = "0.2.4", features = ["js-esbuild"] }
|
50
54
|
```
|
51
55
|
|
56
|
+
Building with the `js-esbuild` feature requires the Go compiler to be installed as well, to build the [JS minifier](https://github.com/evanw/esbuild).
|
57
|
+
|
58
|
+
If the `js-esbuild` feature is not enabled, `cfg.minify_js` will have no effect.
|
59
|
+
|
52
60
|
##### Use
|
53
61
|
|
54
62
|
```rust
|
55
|
-
use hyperbuild::{FriendlyError, hyperbuild};
|
63
|
+
use hyperbuild::{Cfg, FriendlyError, hyperbuild, hyperbuild_copy, hyperbuild_friendly_error, hyperbuild_truncate};
|
56
64
|
|
57
65
|
fn main() {
|
58
66
|
let mut code = b"<p> Hello, world! </p>".to_vec();
|
67
|
+
let cfg = &Cfg {
|
68
|
+
minify_js: false,
|
69
|
+
};
|
59
70
|
|
60
71
|
// Minifies a slice in-place and returns the new minified length,
|
61
72
|
// but leaves any original code after the minified code intact.
|
62
|
-
match hyperbuild(&mut code) {
|
73
|
+
match hyperbuild(&mut code, cfg) {
|
63
74
|
Ok(minified_len) => {}
|
64
75
|
Err((error_type, error_position)) => {}
|
65
76
|
};
|
66
77
|
|
67
78
|
// Creates a vector copy containing only minified code
|
68
79
|
// instead of minifying in-place.
|
69
|
-
match hyperbuild_copy(&code) {
|
80
|
+
match hyperbuild_copy(&code, cfg) {
|
70
81
|
Ok(minified) => {}
|
71
82
|
Err((error_type, error_position)) => {}
|
72
83
|
};
|
73
84
|
|
74
85
|
// Minifies a vector in-place, and then truncates the
|
75
86
|
// vector to the new minified length.
|
76
|
-
match hyperbuild_truncate(&mut code) {
|
87
|
+
match hyperbuild_truncate(&mut code, cfg) {
|
77
88
|
Ok(()) => {}
|
78
89
|
Err((error_type, error_position)) => {}
|
79
90
|
};
|
@@ -81,7 +92,7 @@ fn main() {
|
|
81
92
|
// Identical to `hyperbuild` except with FriendlyError instead.
|
82
93
|
// `code_context` is a string of a visual representation of the source,
|
83
94
|
// with line numbers and position markers to aid in debugging syntax.
|
84
|
-
match hyperbuild_friendly_error(&mut code) {
|
95
|
+
match hyperbuild_friendly_error(&mut code, cfg) {
|
85
96
|
Ok(minified_len) => {}
|
86
97
|
Err(FriendlyError { position, message, code_context }) => {
|
87
98
|
eprintln!("Failed at character {}:", position);
|
@@ -118,10 +129,11 @@ yarn add hyperbuild
|
|
118
129
|
```js
|
119
130
|
const hyperbuild = require("hyperbuild");
|
120
131
|
|
121
|
-
const
|
132
|
+
const cfg = { minifyJs: false };
|
133
|
+
const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
122
134
|
|
123
135
|
// Alternatively, minify in place to avoid copying.
|
124
|
-
const source = Buffer.from("<p> Hello, world! </p>");
|
136
|
+
const source = Buffer.from("<p> Hello, world! </p>", cfg);
|
125
137
|
hyperbuild.minifyInPlace(source);
|
126
138
|
```
|
127
139
|
|
@@ -131,8 +143,9 @@ hyperbuild is also available for TypeScript:
|
|
131
143
|
import * as hyperbuild from "hyperbuild";
|
132
144
|
import * as fs from "fs";
|
133
145
|
|
134
|
-
const
|
135
|
-
hyperbuild.
|
146
|
+
const cfg = { minifyJs: false };
|
147
|
+
const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
148
|
+
hyperbuild.minifyInPlace(fs.readFileSync("source.html"), cfg);
|
136
149
|
```
|
137
150
|
|
138
151
|
</details>
|
@@ -150,7 +163,7 @@ Add as a Maven dependency:
|
|
150
163
|
<dependency>
|
151
164
|
<groupId>in.wilsonl.hyperbuild</groupId>
|
152
165
|
<artifactId>hyperbuild</artifactId>
|
153
|
-
<version>0.
|
166
|
+
<version>0.2.4</version>
|
154
167
|
</dependency>
|
155
168
|
```
|
156
169
|
|
@@ -159,15 +172,18 @@ Add as a Maven dependency:
|
|
159
172
|
```java
|
160
173
|
import in.wilsonl.hyperbuild.Hyperbuild;
|
161
174
|
|
175
|
+
Hyperbuild.Configuration cfg = new Hyperbuild.Configuration.Builder()
|
176
|
+
.setMinifyJs(false)
|
177
|
+
.build();
|
162
178
|
try {
|
163
|
-
String minified = Hyperbuild.minify("<p> Hello, world! </p>");
|
179
|
+
String minified = Hyperbuild.minify("<p> Hello, world! </p>", cfg);
|
164
180
|
} catch (Hyperbuild.SyntaxException e) {
|
165
181
|
System.err.println(e.getMessage());
|
166
182
|
}
|
167
183
|
|
168
184
|
// Alternatively, minify in place:
|
169
185
|
assert source instanceof ByteBuffer && source.isDirect();
|
170
|
-
Hyperbuild.minifyInPlace(source);
|
186
|
+
Hyperbuild.minifyInPlace(source, cfg);
|
171
187
|
```
|
172
188
|
|
173
189
|
</details>
|
@@ -187,7 +203,7 @@ Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
|
|
187
203
|
import hyperbuild
|
188
204
|
|
189
205
|
try:
|
190
|
-
minified = hyperbuild.minify("<p> Hello, world! </p>")
|
206
|
+
minified = hyperbuild.minify("<p> Hello, world! </p>", minify_js=False)
|
191
207
|
except SyntaxError as e:
|
192
208
|
print(e)
|
193
209
|
```
|
@@ -208,17 +224,13 @@ Add the library as a dependency to `Gemfile` or `*.gemspec`.
|
|
208
224
|
```ruby
|
209
225
|
require 'hyperbuild'
|
210
226
|
|
211
|
-
print Hyperbuild.minify
|
227
|
+
print Hyperbuild.minify("<p> Hello, world! </p>", { :minify_js => false })
|
212
228
|
```
|
213
229
|
|
214
230
|
</details>
|
215
231
|
|
216
232
|
## Minification
|
217
233
|
|
218
|
-
### Configurability
|
219
|
-
|
220
|
-
Configuration of minification is currently WIP across all languages. The behaviour mentioned below is the default.
|
221
|
-
|
222
234
|
### Whitespace
|
223
235
|
|
224
236
|
hyperbuild has advanced context-aware whitespace minification that does things such as:
|
@@ -440,6 +452,8 @@ Numeric entities that do not refer to a valid [Unicode Scalar Value](https://www
|
|
440
452
|
|
441
453
|
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
454
|
|
455
|
+
It's possible to get an unintentional entity after removing comments, e.g. `&am<!-- -->p`.
|
456
|
+
|
443
457
|
Left chevrons after any decoding in text are encoded to `<` if possible or `<` otherwise.
|
444
458
|
|
445
459
|
### Comments
|
@@ -454,7 +468,7 @@ Bangs, [processing instructions](https://en.wikipedia.org/wiki/Processing_Instru
|
|
454
468
|
|
455
469
|
Only UTF-8/ASCII-encoded HTML code is supported.
|
456
470
|
|
457
|
-
hyperbuild
|
471
|
+
hyperbuild does no syntax checking or standards enforcement for performance and code complexity reasons.
|
458
472
|
|
459
473
|
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
474
|
|
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.4
|
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-11 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: []
|