astro-html-minifier-next 0.0.0 → 0.0.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.
- package/dist/index.js +37 -35
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +47 -47
package/dist/index.js
CHANGED
|
@@ -17,45 +17,47 @@ export default function htmlMinifier(options) {
|
|
|
17
17
|
const controller = new AbortController();
|
|
18
18
|
const signal = controller.signal;
|
|
19
19
|
const distPath = fileURLToPath(distUrl);
|
|
20
|
+
const logLineArrow = styleText("green", "▶");
|
|
20
21
|
for (const assetUrls of assets.values()) {
|
|
21
22
|
for (const assetUrl of assetUrls) {
|
|
22
23
|
const assetPath = fileURLToPath(assetUrl);
|
|
23
|
-
if (assetPath.toLowerCase().endsWith(".html")) {
|
|
24
|
-
|
|
25
|
-
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
26
|
-
const html = await readFile(assetPath, {
|
|
27
|
-
encoding: "utf8",
|
|
28
|
-
signal,
|
|
29
|
-
});
|
|
30
|
-
const minifiedHtml = await minifyHtml(html, options);
|
|
31
|
-
const htmlSize = Buffer.byteLength(html, "utf8");
|
|
32
|
-
const minifiedHtmlSize = Buffer.byteLength(minifiedHtml, "utf8");
|
|
33
|
-
if (minifiedHtmlSize >= htmlSize) {
|
|
34
|
-
// No actual file size savings, so we skip writing the file or logging anything.
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
await writeFile(assetPath, minifiedHtml, {
|
|
38
|
-
encoding: "utf8",
|
|
39
|
-
signal,
|
|
40
|
-
});
|
|
41
|
-
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
42
|
-
// Log a nice summary of the minification savings and the time it took.
|
|
43
|
-
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
44
|
-
const savings = htmlSize - minifiedHtmlSize;
|
|
45
|
-
const savingsStr = savings < 1000
|
|
46
|
-
? `${savings}B`
|
|
47
|
-
: savings < 1000000
|
|
48
|
-
? `${(savings / 1000).toFixed(1)}kB`
|
|
49
|
-
: `${(savings / 1000000).toFixed(2)}MB`;
|
|
50
|
-
const time = timeEnd - timeStart;
|
|
51
|
-
const timeStr = time < 1000
|
|
52
|
-
? `${Math.round(time)}ms`
|
|
53
|
-
: `${(time / 1000).toFixed(2)}s`;
|
|
54
|
-
logger.info(styleText("green", " ▶") +
|
|
55
|
-
` /${relativeAssetPath} ` +
|
|
56
|
-
styleText("dim", `(-${savingsStr}) (+${timeStr})`));
|
|
57
|
-
});
|
|
24
|
+
if (!assetPath.toLowerCase().endsWith(".html")) {
|
|
25
|
+
continue;
|
|
58
26
|
}
|
|
27
|
+
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
28
|
+
const logLineAssetPath = ` ${logLineArrow} /${relativeAssetPath} `;
|
|
29
|
+
tasks.push(async () => {
|
|
30
|
+
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
31
|
+
const html = await readFile(assetPath, {
|
|
32
|
+
encoding: "utf8",
|
|
33
|
+
signal,
|
|
34
|
+
});
|
|
35
|
+
const minifiedHtml = await minifyHtml(html, options);
|
|
36
|
+
const htmlSize = Buffer.byteLength(html);
|
|
37
|
+
const minifiedHtmlSize = Buffer.byteLength(minifiedHtml);
|
|
38
|
+
if (minifiedHtmlSize >= htmlSize) {
|
|
39
|
+
// No actual file size savings, so we skip writing the file or logging anything.
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
await writeFile(assetPath, minifiedHtml, {
|
|
43
|
+
encoding: "utf8",
|
|
44
|
+
signal,
|
|
45
|
+
});
|
|
46
|
+
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
47
|
+
// Log a nice summary of the minification savings and the time it took.
|
|
48
|
+
const savings = htmlSize - minifiedHtmlSize;
|
|
49
|
+
const savingsStr = savings < 1000
|
|
50
|
+
? `${savings}B`
|
|
51
|
+
: savings < 1000000
|
|
52
|
+
? `${(savings / 1000).toFixed(1)}kB`
|
|
53
|
+
: `${(savings / 1000000).toFixed(2)}MB`;
|
|
54
|
+
const time = timeEnd - timeStart;
|
|
55
|
+
const timeStr = time < 1000
|
|
56
|
+
? `${Math.round(time)}ms`
|
|
57
|
+
: `${(time / 1000).toFixed(2)}s`;
|
|
58
|
+
logger.info(logLineAssetPath +
|
|
59
|
+
styleText("dim", `(-${savingsStr}) (+${timeStr})`));
|
|
60
|
+
});
|
|
59
61
|
}
|
|
60
62
|
}
|
|
61
63
|
// We retrieve the available parallelism from the OS, even if we don't actually run the tasks in different threads.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,oBAAoB,IAAI,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAC1E,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAEN,MAAM,IAAI,UAAU,GACpB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAA4B;IAE5B,+EAA+E;IAC/E,OAAO;QACN,IAAI,EAAE,0BAA0B;QAChC,KAAK,EAAE;YACN,kBAAkB,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE;gBAC9D,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,yBAAyB,CAAC,CAAC,CAAC;gBAExE,MAAM,cAAc,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC,CAAC,4BAA4B;gBAEtE,qBAAqB;gBACrB,MAAM,KAAK,G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{
|
|
2
2
|
"name": "astro-html-minifier-next",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Astro integration for html-minifier-next",
|
|
5
5
|
"homepage": "https://github.com/jonasgeiler/astro-html-minifier-next#readme",
|
|
6
6
|
"bugs": "https://github.com/jonasgeiler/astro-html-minifier-next/issues",
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
"astro": "^5.0.0"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"html-minifier-next": "^2.1.8"
|
|
21
|
+
"html-minifier-next": "^2.1.8",
|
|
22
|
+
"@types/html-minifier-next": "^2.1.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@biomejs/biome": "2.2.6",
|
|
25
|
-
"@types/html-minifier-next": "2.1.0",
|
|
26
26
|
"@types/node": "24.7.2",
|
|
27
27
|
"astro": "5.14.5",
|
|
28
28
|
"typescript": "5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -26,57 +26,57 @@ export default function htmlMinifier(
|
|
|
26
26
|
const controller = new AbortController();
|
|
27
27
|
const signal = controller.signal;
|
|
28
28
|
const distPath = fileURLToPath(distUrl);
|
|
29
|
+
const logLineArrow = styleText("green", "▶");
|
|
29
30
|
for (const assetUrls of assets.values()) {
|
|
30
31
|
for (const assetUrl of assetUrls) {
|
|
31
32
|
const assetPath = fileURLToPath(assetUrl);
|
|
32
|
-
if (assetPath.toLowerCase().endsWith(".html")) {
|
|
33
|
-
|
|
34
|
-
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
35
|
-
|
|
36
|
-
const html = await readFile(assetPath, {
|
|
37
|
-
encoding: "utf8",
|
|
38
|
-
signal,
|
|
39
|
-
});
|
|
40
|
-
const minifiedHtml = await minifyHtml(html, options);
|
|
41
|
-
|
|
42
|
-
const htmlSize = Buffer.byteLength(html, "utf8");
|
|
43
|
-
const minifiedHtmlSize = Buffer.byteLength(
|
|
44
|
-
minifiedHtml,
|
|
45
|
-
"utf8",
|
|
46
|
-
);
|
|
47
|
-
if (minifiedHtmlSize >= htmlSize) {
|
|
48
|
-
// No actual file size savings, so we skip writing the file or logging anything.
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
await writeFile(assetPath, minifiedHtml, {
|
|
53
|
-
encoding: "utf8",
|
|
54
|
-
signal,
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
58
|
-
|
|
59
|
-
// Log a nice summary of the minification savings and the time it took.
|
|
60
|
-
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
61
|
-
const savings = htmlSize - minifiedHtmlSize;
|
|
62
|
-
const savingsStr =
|
|
63
|
-
savings < 1000
|
|
64
|
-
? `${savings}B`
|
|
65
|
-
: savings < 1000000
|
|
66
|
-
? `${(savings / 1000).toFixed(1)}kB`
|
|
67
|
-
: `${(savings / 1000000).toFixed(2)}MB`;
|
|
68
|
-
const time = timeEnd - timeStart;
|
|
69
|
-
const timeStr =
|
|
70
|
-
time < 1000
|
|
71
|
-
? `${Math.round(time)}ms`
|
|
72
|
-
: `${(time / 1000).toFixed(2)}s`;
|
|
73
|
-
logger.info(
|
|
74
|
-
styleText("green", " ▶") +
|
|
75
|
-
` /${relativeAssetPath} ` +
|
|
76
|
-
styleText("dim", `(-${savingsStr}) (+${timeStr})`),
|
|
77
|
-
);
|
|
78
|
-
});
|
|
33
|
+
if (!assetPath.toLowerCase().endsWith(".html")) {
|
|
34
|
+
continue;
|
|
79
35
|
}
|
|
36
|
+
|
|
37
|
+
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
38
|
+
const logLineAssetPath = ` ${logLineArrow} /${relativeAssetPath} `;
|
|
39
|
+
tasks.push(async () => {
|
|
40
|
+
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
41
|
+
|
|
42
|
+
const html = await readFile(assetPath, {
|
|
43
|
+
encoding: "utf8",
|
|
44
|
+
signal,
|
|
45
|
+
});
|
|
46
|
+
const minifiedHtml = await minifyHtml(html, options);
|
|
47
|
+
|
|
48
|
+
const htmlSize = Buffer.byteLength(html);
|
|
49
|
+
const minifiedHtmlSize = Buffer.byteLength(minifiedHtml);
|
|
50
|
+
if (minifiedHtmlSize >= htmlSize) {
|
|
51
|
+
// No actual file size savings, so we skip writing the file or logging anything.
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
await writeFile(assetPath, minifiedHtml, {
|
|
56
|
+
encoding: "utf8",
|
|
57
|
+
signal,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
61
|
+
|
|
62
|
+
// Log a nice summary of the minification savings and the time it took.
|
|
63
|
+
const savings = htmlSize - minifiedHtmlSize;
|
|
64
|
+
const savingsStr =
|
|
65
|
+
savings < 1000
|
|
66
|
+
? `${savings}B`
|
|
67
|
+
: savings < 1000000
|
|
68
|
+
? `${(savings / 1000).toFixed(1)}kB`
|
|
69
|
+
: `${(savings / 1000000).toFixed(2)}MB`;
|
|
70
|
+
const time = timeEnd - timeStart;
|
|
71
|
+
const timeStr =
|
|
72
|
+
time < 1000
|
|
73
|
+
? `${Math.round(time)}ms`
|
|
74
|
+
: `${(time / 1000).toFixed(2)}s`;
|
|
75
|
+
logger.info(
|
|
76
|
+
logLineAssetPath +
|
|
77
|
+
styleText("dim", `(-${savingsStr}) (+${timeStr})`),
|
|
78
|
+
);
|
|
79
|
+
});
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|