fix: gracefully handle htmlmin parse errors instead of crashing build

Malformed HTML (e.g. unescaped quotes in iframe title attributes) caused
html-minifier-terser to throw a fatal parse error, killing the entire
Eleventy build. Now catches the error, logs a warning, and returns the
unminified content so the build completes.
This commit is contained in:
Ricardo
2026-02-18 09:59:00 +01:00
parent 8503237d4d
commit e5b0fd7dc6
+5
View File
@@ -220,6 +220,7 @@ export default function (eleventyConfig) {
// HTML minification — only during initial build, skip during watch rebuilds
eleventyConfig.addTransform("htmlmin", async function (content, outputPath) {
if (outputPath && outputPath.endsWith(".html") && process.env.ELEVENTY_RUN_MODE === "build") {
try {
return await minify(content, {
collapseWhitespace: true,
removeComments: true,
@@ -228,6 +229,10 @@ export default function (eleventyConfig) {
minifyCSS: false,
minifyJS: false,
});
} catch {
console.warn(`[htmlmin] Parse error in ${outputPath}, skipping minification`);
return content;
}
}
return content;
});