mirror of
https://github.com/svemagie/blog-eleventy-indiekit.git
synced 2026-05-15 06:58:50 +02:00
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:
+13
-8
@@ -220,14 +220,19 @@ 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") {
|
||||
return await minify(content, {
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
html5: true,
|
||||
decodeEntities: true,
|
||||
minifyCSS: false,
|
||||
minifyJS: false,
|
||||
});
|
||||
try {
|
||||
return await minify(content, {
|
||||
collapseWhitespace: true,
|
||||
removeComments: true,
|
||||
html5: true,
|
||||
decodeEntities: true,
|
||||
minifyCSS: false,
|
||||
minifyJS: false,
|
||||
});
|
||||
} catch {
|
||||
console.warn(`[htmlmin] Parse error in ${outputPath}, skipping minification`);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
return content;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user