eleventy-chirpy-blog-template/_11ty/html-minify.js
2025-06-25 14:09:10 +02:00

26 lines
610 B
JavaScript

// Transformer to minify HTML output.
const htmlmin = require("html-minifier");
const convert = async (rawContent, outputPath) => {
const content = rawContent;
if (outputPath && outputPath.endsWith(".html")) {
const minified = htmlmin.minify(content, {
useShortDoctype: true,
removeComments: true,
collapseWhitespace: true
});
return minified;
}
return content;
};
module.exports = {
initArguments: {},
configFunction: async (eleventyConfig = {}) => {
eleventyConfig.addTransform("minifyHTML", convert);
}
};