Super-fast HTML minifier - platform-specific native Node.js addon for Linux ARM gnueabihf architecture
npx @tessl/cli install tessl/npm-swc--html-linux-arm-gnueabihf@1.13.00
# SWC HTML Linux ARM
1
2
SWC HTML Linux ARM is a platform-specific native Node.js addon that provides super-fast HTML minification capabilities for Linux ARM gnueabihf architecture systems. It's part of the SWC (Speedy Web Compiler) ecosystem and contains a compiled native binary that exposes HTML minification functionality through Rust-powered Node.js bindings, offering optimal performance through native implementation.
3
4
## Package Information
5
6
- **Package Name**: @swc/html-linux-arm-gnueabihf
7
- **Package Type**: npm
8
- **Language**: TypeScript/Rust (native addon)
9
- **Installation**: Automatically installed as optional dependency of `@swc/html`
10
- **Architecture**: Linux ARM gnueabihf
11
- **Node.js**: >=10
12
13
## Core Imports
14
15
```typescript
16
import { minify, minifySync, minifyFragment, minifyFragmentSync } from "@swc/html";
17
import type { Options, FragmentOptions, TransformOutput } from "@swc/html";
18
```
19
20
For CommonJS:
21
22
```javascript
23
const { minify, minifySync, minifyFragment, minifyFragmentSync } = require("@swc/html");
24
```
25
26
## Basic Usage
27
28
```typescript
29
import { minify, minifySync } from "@swc/html";
30
31
// Asynchronous HTML minification
32
const result = await minify(`
33
<html>
34
<head>
35
<title> Example </title>
36
</head>
37
<body>
38
<p> Hello World </p>
39
</body>
40
</html>
41
`, {
42
collapseWhitespaces: "smart",
43
removeComments: true
44
});
45
46
console.log(result.code);
47
// <html><head><title>Example</title></head><body><p>Hello World</p></body></html>
48
49
// Synchronous HTML minification
50
const syncResult = minifySync('<p> Hello </p>', {
51
collapseWhitespaces: "all"
52
});
53
54
console.log(syncResult.code);
55
// <p>Hello</p>
56
```
57
58
## Architecture
59
60
SWC HTML Linux ARM is structured around several key components:
61
62
- **Platform-Specific Binary**: Native `.node` file (`swc-html.linux-arm-gnueabihf.node`) compiled from Rust
63
- **TypeScript Interface**: Type-safe wrapper providing async/sync APIs for both documents and fragments
64
- **Native Bindings**: NAPI-RS powered bindings connecting TypeScript API to Rust implementation
65
- **Minification Engine**: Rust-based HTML parser, minifier, and code generator with CSS/JS integration
66
- **Optional Dependency**: Automatically installed when main `@swc/html` package detects compatible ARM Linux system
67
68
## Capabilities
69
70
### HTML Document Minification
71
72
Complete HTML document processing with comprehensive minification options.
73
74
```typescript { .api }
75
/**
76
* Asynchronously minifies complete HTML documents
77
* @param content - HTML content as string or Buffer
78
* @param options - Minification configuration options
79
* @returns Promise resolving to minified HTML with optional errors
80
*/
81
function minify(
82
content: string | Buffer,
83
options?: Options
84
): Promise<TransformOutput>;
85
86
/**
87
* Synchronously minifies complete HTML documents
88
* @param content - HTML content as string or Buffer
89
* @param options - Minification configuration options
90
* @returns Minified HTML with optional errors
91
*/
92
function minifySync(
93
content: string | Buffer,
94
options?: Options
95
): TransformOutput;
96
```
97
98
**Usage Examples:**
99
100
```typescript
101
import { minify, minifySync } from "@swc/html";
102
103
// Advanced minification with CSS and JS
104
const advancedResult = await minify(`
105
<!DOCTYPE html>
106
<html>
107
<head>
108
<style>
109
body { margin: 0; padding: 10px; }
110
.highlight { background: yellow; }
111
</style>
112
<script>
113
function greet() {
114
console.log("Hello World");
115
}
116
</script>
117
</head>
118
<body class="container">
119
<h1 id="title">Welcome</h1>
120
<p>This is a paragraph with lots of whitespace.</p>
121
<!-- This comment will be removed -->
122
<button onclick="greet()">Click me</button>
123
</body>
124
</html>
125
`, {
126
collapseWhitespaces: "smart",
127
removeComments: true,
128
minifyCss: true,
129
minifyJs: true,
130
removeEmptyAttributes: true,
131
collapseBooleanAttributes: true
132
});
133
134
// Minimal configuration for quick processing
135
const quickResult = minifySync('<p> Simple text </p>', {
136
collapseWhitespaces: "all"
137
});
138
```
139
140
### HTML Fragment Minification
141
142
HTML fragment processing with proper parsing context and document mode support.
143
144
```typescript { .api }
145
/**
146
* Asynchronously minifies HTML fragments with parsing context
147
* @param content - HTML fragment content as string or Buffer
148
* @param options - Fragment minification options with context
149
* @returns Promise resolving to minified HTML fragment
150
*/
151
function minifyFragment(
152
content: string | Buffer,
153
options?: FragmentOptions
154
): Promise<TransformOutput>;
155
156
/**
157
* Synchronously minifies HTML fragments with parsing context
158
* @param content - HTML fragment content as string or Buffer
159
* @param options - Fragment minification options with context
160
* @returns Minified HTML fragment
161
*/
162
function minifyFragmentSync(
163
content: string | Buffer,
164
options?: FragmentOptions
165
): TransformOutput;
166
```
167
168
**Usage Examples:**
169
170
```typescript
171
import { minifyFragment, minifyFragmentSync } from "@swc/html";
172
173
// Fragment with context element
174
const listFragment = await minifyFragment(`
175
<li class="item"> First item </li>
176
<li class="item"> Second item </li>
177
`, {
178
collapseWhitespaces: "smart",
179
context_element: {
180
tagName: "ul",
181
namespace: "http://www.w3.org/1999/xhtml",
182
attributes: [],
183
isSelfClosing: false
184
}
185
});
186
187
// Table fragment with form context
188
const tableFragment = minifyFragmentSync(`
189
<tr>
190
<td><input type="text" name="username" required /></td>
191
<td><input type="email" name="email" /></td>
192
</tr>
193
`, {
194
collapseWhitespaces: "all",
195
collapseBooleanAttributes: true,
196
context_element: {
197
tagName: "table",
198
namespace: "http://www.w3.org/1999/xhtml",
199
attributes: [],
200
isSelfClosing: false
201
},
202
form_element: {
203
tagName: "form",
204
namespace: "http://www.w3.org/1999/xhtml",
205
attributes: [],
206
isSelfClosing: false
207
}
208
});
209
```
210
211
## Types
212
213
```typescript { .api }
214
/**
215
* Minification configuration options for HTML documents
216
*/
217
interface Options {
218
/** Optional filename for debugging purposes */
219
filename?: string;
220
/** Whether content is from iframe srcdoc attribute */
221
iframeSrcdoc?: boolean;
222
/** Enable/disable JavaScript processing during parsing */
223
scriptingEnabled?: boolean;
224
/** Force HTML5 doctype in output */
225
forceSetHtml5Doctype?: boolean;
226
/** Whitespace collapse strategy */
227
collapseWhitespaces?:
228
| "none"
229
| "all"
230
| "smart"
231
| "conservative"
232
| "advanced-conservative"
233
| "only-metadata";
234
/** Remove empty metadata elements (script, style, meta, link without content/attributes) */
235
removeEmptyMetadataElements?: boolean;
236
/** Remove HTML comments */
237
removeComments?: boolean;
238
/** Regex patterns for comments to preserve (e.g., license comments) */
239
preserveComments?: string[];
240
/** Minify conditional IE comments */
241
minifyConditionalComments?: boolean;
242
/** Remove empty HTML attributes */
243
removeEmptyAttributes?: boolean;
244
/** Remove redundant HTML attributes */
245
removeRedundantAttributes?: "none" | "all" | "smart";
246
/** Collapse boolean attributes (e.g., disabled="disabled" -> disabled) */
247
collapseBooleanAttributes?: boolean;
248
/** Normalize attribute values and names */
249
normalizeAttributes?: boolean;
250
/** JSON minification configuration */
251
minifyJson?: boolean | { pretty?: boolean };
252
/** JavaScript minification configuration */
253
minifyJs?: boolean | { parser?: any; minifier?: any; codegen?: any };
254
/** CSS minification configuration */
255
minifyCss?:
256
| boolean
257
| { lib: "lightningcss" }
258
| { lib: "swc"; parser?: any; minifier?: any; codegen?: any };
259
/** Additional script content patterns to minify */
260
minifyAdditionalScriptsContent?: [string, MinifierType][];
261
/** Additional attribute patterns to minify */
262
minifyAdditionalAttributes?: [string, MinifierType][];
263
/** Sort space-separated attribute values alphabetically */
264
sortSpaceSeparatedAttributeValues?: boolean;
265
/** Sort attributes alphabetically */
266
sortAttributes?: boolean;
267
/** Enable HTML tag omission optimization */
268
tagOmission?: boolean | "keep-head-and-body";
269
/** Use self-closing syntax for void elements */
270
selfClosingVoidElements?: boolean;
271
/** Quote handling for attributes */
272
quotes?: boolean;
273
}
274
275
/**
276
* Extended options for HTML fragment minification
277
*/
278
interface FragmentOptions extends Options {
279
/** Document parsing mode for fragment context */
280
mode?: "no-quirks" | "limited-quirks" | "quirks";
281
/** Context element for fragment parsing (defaults to template element) */
282
context_element?: Element;
283
/** Form element context for parsing form-related fragments */
284
form_element?: Element;
285
}
286
287
/**
288
* Supported minifier types for additional content processing
289
*/
290
type MinifierType = "js-module" | "js-script" | "json" | "css" | "html";
291
292
/**
293
* Result of HTML minification operation
294
*/
295
interface TransformOutput {
296
/** Minified HTML code */
297
code: string;
298
/** Optional array of parsing/processing errors and warnings */
299
errors?: Diagnostic[];
300
}
301
302
/**
303
* HTML element representation for parsing context
304
*/
305
interface Element {
306
/** Element tag name */
307
tagName: string;
308
/** Element namespace URI */
309
namespace: string;
310
/** Element attributes */
311
attributes: Attribute[];
312
/** Whether element uses self-closing syntax */
313
isSelfClosing: boolean;
314
}
315
316
/**
317
* HTML attribute representation
318
*/
319
interface Attribute {
320
/** Optional attribute namespace */
321
namespace?: string;
322
/** Optional attribute prefix */
323
prefix?: string;
324
/** Attribute name */
325
name: string;
326
/** Optional attribute value */
327
value?: string;
328
}
329
330
/**
331
* Diagnostic information for errors and warnings
332
*/
333
interface Diagnostic {
334
/** Diagnostic level (error, warning, info) */
335
level: string;
336
/** Human-readable diagnostic message */
337
message: string;
338
/** Source code location information */
339
span: any;
340
}
341
```
342
343
## Error Handling
344
345
The minification functions can encounter various types of errors during HTML parsing and processing:
346
347
```typescript
348
import { minify } from "@swc/html";
349
350
try {
351
const result = await minify('<div><p>Unclosed paragraph</div>');
352
353
// Check for parsing errors
354
if (result.errors && result.errors.length > 0) {
355
result.errors.forEach(error => {
356
console.warn(`${error.level}: ${error.message}`);
357
});
358
}
359
360
console.log(result.code);
361
} catch (error) {
362
console.error('Minification failed:', error);
363
}
364
```
365
366
Common error scenarios:
367
- **Malformed HTML**: Invalid tag structures, mismatched quotes
368
- **Invalid Options**: Unsupported configuration values
369
- **Memory Issues**: Extremely large input files
370
- **Context Errors**: Invalid context_element or form_element in fragment options