From d1607c74e3e29e52d2004ae062f3ec5f515c9d0f Mon Sep 17 00:00:00 2001 From: eggy Date: Sat, 10 Jul 2021 22:25:31 -0400 Subject: [PATCH] Minify html --- .eleventy.js | 12 ++++++++++++ package.json | 3 ++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.eleventy.js b/.eleventy.js index 38e390e..0762fce 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,10 +1,22 @@ const syntaxHighlight = require('@11ty/eleventy-plugin-syntaxhighlight') const markdownIt = require('markdown-it') const markdownItAnchor = require('markdown-it-anchor') +const htmlmin = require("html-minifier") module.exports = function(eleventyConfig) { // Plugins eleventyConfig.addPlugin(syntaxHighlight) + eleventyConfig.addTransform("htmlmin", (content, outputPath) => { + if (outputPath.endsWith(".html")) { + return htmlmin.minify(content, { + collapseWhitespace: true, + removeComments: true, + useShortDoctype: true, + }); + } + + return content; + }); // To enable merging of tags eleventyConfig.setDataDeepMerge(true) diff --git a/package.json b/package.json index 67a80ec..a5dbd83 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "devDependencies": { "@11ty/eleventy": ">=0.11.1", "@11ty/eleventy-plugin-syntaxhighlight": ">=3.0.4", - "eslint": ">=7.12.1" + "eslint": ">=7.12.1", + "html-minifier": ">=3.5.21" }, "dependencies": { "@tailwindcss/typography": "^0.4.0",