astro-html-minifier-next 4.0.0 → 4.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.d.ts.map +1 -1
- package/dist/index.js +57 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +80 -50
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,oBAAoB,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC3D;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAO,GAAE,mBAAwB,GAC/B,gBAAgB,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAwB,MAAM,oBAAoB,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,WAAW,mBAAoB,SAAQ,eAAe;IAC3D;;;;;;;;OAQG;IACH,uBAAuB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CACnC,OAAO,GAAE,mBAAwB,GAC/B,gBAAgB,CAoLlB"}
|
package/dist/index.js
CHANGED
|
@@ -38,44 +38,67 @@ export default function htmlMinifier(options = {}) {
|
|
|
38
38
|
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
39
39
|
const logLineAssetPath = ` ${logLineArrow} /${relativeAssetPath} `;
|
|
40
40
|
tasks.push(async () => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
signal,
|
|
45
|
-
});
|
|
46
|
-
const minifiedHTML = await minifyHTML(html, minifyHTMLOptions);
|
|
47
|
-
const savings = Buffer.byteLength(html) - Buffer.byteLength(minifiedHTML);
|
|
48
|
-
const hasSavings = savings > 0;
|
|
49
|
-
if (hasSavings || alwaysWriteMinifiedHTML) {
|
|
50
|
-
// Only write the minified HTML to the file if it's smaller,
|
|
51
|
-
// or if alwaysWriteMinifiedHTML is enabled.
|
|
52
|
-
await writeFile(assetPath, minifiedHTML, {
|
|
41
|
+
try {
|
|
42
|
+
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
43
|
+
const html = await readFile(assetPath, {
|
|
53
44
|
encoding: "utf8",
|
|
54
45
|
signal,
|
|
55
46
|
});
|
|
47
|
+
const minifiedHTML = await minifyHTML(html, minifyHTMLOptions);
|
|
48
|
+
const savings = Buffer.byteLength(html) - Buffer.byteLength(minifiedHTML);
|
|
49
|
+
const hasSavings = savings > 0;
|
|
50
|
+
if (hasSavings || alwaysWriteMinifiedHTML) {
|
|
51
|
+
// Only write the minified HTML to the file if it's smaller,
|
|
52
|
+
// or if alwaysWriteMinifiedHTML is enabled.
|
|
53
|
+
await writeFile(assetPath, minifiedHTML, {
|
|
54
|
+
encoding: "utf8",
|
|
55
|
+
signal,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
59
|
+
const time = timeEnd - timeStart;
|
|
60
|
+
// Log a nice summary of the minification savings and the time it
|
|
61
|
+
// took.
|
|
62
|
+
const savingsSign = hasSavings ? "-" : "+";
|
|
63
|
+
const savingsAbs = Math.abs(savings);
|
|
64
|
+
const savingsWithUnit = savingsAbs < 1024
|
|
65
|
+
? `${savingsAbs}B`
|
|
66
|
+
: savingsAbs < 1048576
|
|
67
|
+
? `${(savingsAbs / 1024).toFixed(1)}kB`
|
|
68
|
+
: `${(savingsAbs / 1048576).toFixed(2)}MB`;
|
|
69
|
+
const timeWithUnit = time < 1000
|
|
70
|
+
? `${Math.round(time)}ms`
|
|
71
|
+
: `${(time / 1000).toFixed(2)}s`;
|
|
72
|
+
const savingsNote = hasSavings || alwaysWriteMinifiedHTML
|
|
73
|
+
? hasSavings
|
|
74
|
+
? ""
|
|
75
|
+
: ", always write enabled"
|
|
76
|
+
: ", skipped";
|
|
77
|
+
logger.info(logLineAssetPath +
|
|
78
|
+
styleText(hasSavings ? "dim" : "yellow", `(${savingsSign}${savingsWithUnit}${savingsNote}) `) +
|
|
79
|
+
styleText("dim", `(+${timeWithUnit}) (${++tasksDone}/${tasksTotal})`));
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
// We log which file the error happened in, to make debugging
|
|
83
|
+
// easier, and then rethrow it.
|
|
84
|
+
const isAborted = signal.aborted &&
|
|
85
|
+
error instanceof Error &&
|
|
86
|
+
error.name === "AbortError" &&
|
|
87
|
+
error.message === "The operation was aborted";
|
|
88
|
+
const errorLogLineArrow = styleText(isAborted ? "yellow" : "red", "▶");
|
|
89
|
+
const errorLogLineAssetPath = ` ${errorLogLineArrow} /${relativeAssetPath} `;
|
|
90
|
+
logger.info(errorLogLineAssetPath +
|
|
91
|
+
(isAborted
|
|
92
|
+
? styleText("yellow", "ABORTED ")
|
|
93
|
+
: styleText("red", "ERROR ") +
|
|
94
|
+
styleText("dim",
|
|
95
|
+
// Turning the error into a string and then encoding
|
|
96
|
+
// to JSON makes it into a nice single-line message.
|
|
97
|
+
// The stack trace gets logged after we rethrow.
|
|
98
|
+
`(${JSON.stringify(String(error))}) `)) +
|
|
99
|
+
styleText("dim", `(${++tasksDone}/${tasksTotal})`));
|
|
100
|
+
throw error;
|
|
56
101
|
}
|
|
57
|
-
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
58
|
-
const time = timeEnd - timeStart;
|
|
59
|
-
// Log a nice summary of the minification savings and the time it
|
|
60
|
-
// took.
|
|
61
|
-
const savingsSign = hasSavings ? "-" : "+";
|
|
62
|
-
const savingsAbs = Math.abs(savings);
|
|
63
|
-
const savingsWithUnit = savingsAbs < 1024
|
|
64
|
-
? `${savingsAbs}B`
|
|
65
|
-
: savingsAbs < 1048576
|
|
66
|
-
? `${(savingsAbs / 1024).toFixed(1)}kB`
|
|
67
|
-
: `${(savingsAbs / 1048576).toFixed(2)}MB`;
|
|
68
|
-
const timeWithUnit = time < 1000
|
|
69
|
-
? `${Math.round(time)}ms`
|
|
70
|
-
: `${(time / 1000).toFixed(2)}s`;
|
|
71
|
-
const savingsNote = hasSavings || alwaysWriteMinifiedHTML
|
|
72
|
-
? hasSavings
|
|
73
|
-
? ""
|
|
74
|
-
: ", always write enabled"
|
|
75
|
-
: ", skipped";
|
|
76
|
-
logger.info(logLineAssetPath +
|
|
77
|
-
styleText(hasSavings ? "dim" : "yellow", `(${savingsSign}${savingsWithUnit}${savingsNote}) `) +
|
|
78
|
-
styleText("dim", `(+${timeWithUnit}) (${++tasksDone}/${tasksTotal})`));
|
|
79
102
|
});
|
|
80
103
|
tasksTotal++;
|
|
81
104
|
}
|
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,EAAwB,MAAM,IAAI,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAqBhF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UA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,CAAC;SACD;KACD,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-html-minifier-next",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"description": "Minify Astro HTML assets using 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",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"html-minifier-next": "^5.2.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "2.4.
|
|
24
|
+
"@biomejs/biome": "2.4.9",
|
|
25
25
|
"@types/node": "25.5.0",
|
|
26
26
|
"astro": "6.0.7",
|
|
27
27
|
"typescript": "5.9.3"
|
package/src/index.ts
CHANGED
|
@@ -73,60 +73,90 @@ export default function htmlMinifier(
|
|
|
73
73
|
const relativeAssetPath = getRelativePath(distPath, assetPath);
|
|
74
74
|
const logLineAssetPath = ` ${logLineArrow} /${relativeAssetPath} `;
|
|
75
75
|
tasks.push(async () => {
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
signal,
|
|
81
|
-
});
|
|
82
|
-
const minifiedHTML = await minifyHTML(html, minifyHTMLOptions);
|
|
83
|
-
|
|
84
|
-
const savings =
|
|
85
|
-
Buffer.byteLength(html) - Buffer.byteLength(minifiedHTML);
|
|
86
|
-
const hasSavings = savings > 0;
|
|
87
|
-
if (hasSavings || alwaysWriteMinifiedHTML) {
|
|
88
|
-
// Only write the minified HTML to the file if it's smaller,
|
|
89
|
-
// or if alwaysWriteMinifiedHTML is enabled.
|
|
90
|
-
await writeFile(assetPath, minifiedHTML, {
|
|
76
|
+
try {
|
|
77
|
+
const timeStart = performance.now(); // --- TIMED BLOCK START ---
|
|
78
|
+
|
|
79
|
+
const html = await readFile(assetPath, {
|
|
91
80
|
encoding: "utf8",
|
|
92
81
|
signal,
|
|
93
82
|
});
|
|
83
|
+
const minifiedHTML = await minifyHTML(html, minifyHTMLOptions);
|
|
84
|
+
|
|
85
|
+
const savings =
|
|
86
|
+
Buffer.byteLength(html) - Buffer.byteLength(minifiedHTML);
|
|
87
|
+
const hasSavings = savings > 0;
|
|
88
|
+
if (hasSavings || alwaysWriteMinifiedHTML) {
|
|
89
|
+
// Only write the minified HTML to the file if it's smaller,
|
|
90
|
+
// or if alwaysWriteMinifiedHTML is enabled.
|
|
91
|
+
await writeFile(assetPath, minifiedHTML, {
|
|
92
|
+
encoding: "utf8",
|
|
93
|
+
signal,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
98
|
+
const time = timeEnd - timeStart;
|
|
99
|
+
|
|
100
|
+
// Log a nice summary of the minification savings and the time it
|
|
101
|
+
// took.
|
|
102
|
+
const savingsSign = hasSavings ? "-" : "+";
|
|
103
|
+
const savingsAbs = Math.abs(savings);
|
|
104
|
+
const savingsWithUnit =
|
|
105
|
+
savingsAbs < 1024
|
|
106
|
+
? `${savingsAbs}B`
|
|
107
|
+
: savingsAbs < 1048576
|
|
108
|
+
? `${(savingsAbs / 1024).toFixed(1)}kB`
|
|
109
|
+
: `${(savingsAbs / 1048576).toFixed(2)}MB`;
|
|
110
|
+
const timeWithUnit =
|
|
111
|
+
time < 1000
|
|
112
|
+
? `${Math.round(time)}ms`
|
|
113
|
+
: `${(time / 1000).toFixed(2)}s`;
|
|
114
|
+
const savingsNote =
|
|
115
|
+
hasSavings || alwaysWriteMinifiedHTML
|
|
116
|
+
? hasSavings
|
|
117
|
+
? ""
|
|
118
|
+
: ", always write enabled"
|
|
119
|
+
: ", skipped";
|
|
120
|
+
logger.info(
|
|
121
|
+
logLineAssetPath +
|
|
122
|
+
styleText(
|
|
123
|
+
hasSavings ? "dim" : "yellow",
|
|
124
|
+
`(${savingsSign}${savingsWithUnit}${savingsNote}) `,
|
|
125
|
+
) +
|
|
126
|
+
styleText(
|
|
127
|
+
"dim",
|
|
128
|
+
`(+${timeWithUnit}) (${++tasksDone}/${tasksTotal})`,
|
|
129
|
+
),
|
|
130
|
+
);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
// We log which file the error happened in, to make debugging
|
|
133
|
+
// easier, and then rethrow it.
|
|
134
|
+
const isAborted =
|
|
135
|
+
signal.aborted &&
|
|
136
|
+
error instanceof Error &&
|
|
137
|
+
error.name === "AbortError" &&
|
|
138
|
+
error.message === "The operation was aborted";
|
|
139
|
+
const errorLogLineArrow = styleText(
|
|
140
|
+
isAborted ? "yellow" : "red",
|
|
141
|
+
"▶",
|
|
142
|
+
);
|
|
143
|
+
const errorLogLineAssetPath = ` ${errorLogLineArrow} /${relativeAssetPath} `;
|
|
144
|
+
logger.info(
|
|
145
|
+
errorLogLineAssetPath +
|
|
146
|
+
(isAborted
|
|
147
|
+
? styleText("yellow", "ABORTED ")
|
|
148
|
+
: styleText("red", "ERROR ") +
|
|
149
|
+
styleText(
|
|
150
|
+
"dim",
|
|
151
|
+
// Turning the error into a string and then encoding
|
|
152
|
+
// to JSON makes it into a nice single-line message.
|
|
153
|
+
// The stack trace gets logged after we rethrow.
|
|
154
|
+
`(${JSON.stringify(String(error))}) `,
|
|
155
|
+
)) +
|
|
156
|
+
styleText("dim", `(${++tasksDone}/${tasksTotal})`),
|
|
157
|
+
);
|
|
158
|
+
throw error;
|
|
94
159
|
}
|
|
95
|
-
|
|
96
|
-
const timeEnd = performance.now(); // --- TIMED BLOCK END ---
|
|
97
|
-
const time = timeEnd - timeStart;
|
|
98
|
-
|
|
99
|
-
// Log a nice summary of the minification savings and the time it
|
|
100
|
-
// took.
|
|
101
|
-
const savingsSign = hasSavings ? "-" : "+";
|
|
102
|
-
const savingsAbs = Math.abs(savings);
|
|
103
|
-
const savingsWithUnit =
|
|
104
|
-
savingsAbs < 1024
|
|
105
|
-
? `${savingsAbs}B`
|
|
106
|
-
: savingsAbs < 1048576
|
|
107
|
-
? `${(savingsAbs / 1024).toFixed(1)}kB`
|
|
108
|
-
: `${(savingsAbs / 1048576).toFixed(2)}MB`;
|
|
109
|
-
const timeWithUnit =
|
|
110
|
-
time < 1000
|
|
111
|
-
? `${Math.round(time)}ms`
|
|
112
|
-
: `${(time / 1000).toFixed(2)}s`;
|
|
113
|
-
const savingsNote =
|
|
114
|
-
hasSavings || alwaysWriteMinifiedHTML
|
|
115
|
-
? hasSavings
|
|
116
|
-
? ""
|
|
117
|
-
: ", always write enabled"
|
|
118
|
-
: ", skipped";
|
|
119
|
-
logger.info(
|
|
120
|
-
logLineAssetPath +
|
|
121
|
-
styleText(
|
|
122
|
-
hasSavings ? "dim" : "yellow",
|
|
123
|
-
`(${savingsSign}${savingsWithUnit}${savingsNote}) `,
|
|
124
|
-
) +
|
|
125
|
-
styleText(
|
|
126
|
-
"dim",
|
|
127
|
-
`(+${timeWithUnit}) (${++tasksDone}/${tasksTotal})`,
|
|
128
|
-
),
|
|
129
|
-
);
|
|
130
160
|
});
|
|
131
161
|
|
|
132
162
|
tasksTotal++;
|