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:
@@ -220,6 +220,7 @@ export default function (eleventyConfig) {
|
|||||||
// HTML minification — only during initial build, skip during watch rebuilds
|
// HTML minification — only during initial build, skip during watch rebuilds
|
||||||
eleventyConfig.addTransform("htmlmin", async function (content, outputPath) {
|
eleventyConfig.addTransform("htmlmin", async function (content, outputPath) {
|
||||||
if (outputPath && outputPath.endsWith(".html") && process.env.ELEVENTY_RUN_MODE === "build") {
|
if (outputPath && outputPath.endsWith(".html") && process.env.ELEVENTY_RUN_MODE === "build") {
|
||||||
|
try {
|
||||||
return await minify(content, {
|
return await minify(content, {
|
||||||
collapseWhitespace: true,
|
collapseWhitespace: true,
|
||||||
removeComments: true,
|
removeComments: true,
|
||||||
@@ -228,6 +229,10 @@ export default function (eleventyConfig) {
|
|||||||
minifyCSS: false,
|
minifyCSS: false,
|
||||||
minifyJS: false,
|
minifyJS: false,
|
||||||
});
|
});
|
||||||
|
} catch {
|
||||||
|
console.warn(`[htmlmin] Parse error in ${outputPath}, skipping minification`);
|
||||||
|
return content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return content;
|
return content;
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user