chore: html minify tweaks

This commit is contained in:
Cory Dransfeldt 2023-12-17 14:21:26 -08:00
parent 92853a6ad2
commit 71eb915918
No known key found for this signature in database
4 changed files with 143 additions and 92 deletions

View file

@ -0,0 +1,17 @@
const htmlmin = require('html-minifier-terser')
const isProduction = process.env.ELEVENTY_ENV === 'production'
module.exports = (eleventyConfig) => {
eleventyConfig.addTransform('html-minify', (content, path) => {
if (path && path.endsWith('.html') && isProduction) {
return htmlmin.minify(content, {
collapseBooleanAttributes: true,
collapseWhitespace: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
removeComments: true,
})
}
return content
})
}