Add HTML minification to Vite

This commit is contained in:
2026-06-24 18:12:17 +02:00
parent 9086e48cea
commit 0ce3f57d2e
4 changed files with 260 additions and 5 deletions
+36
View File
@@ -0,0 +1,36 @@
import { defineConfig } from 'vite';
import { minify } from 'html-minifier-terser';
const htmlMinifyOptions = {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
collapseWhitespace: true,
conservativeCollapse: true,
decodeEntities: true,
minifyCSS: true,
minifyJS: true,
processConditionalComments: true,
removeComments: true,
removeEmptyAttributes: true,
removeOptionalTags: true,
removeRedundantAttributes: true,
sortAttributes: true,
sortClassName: true,
useShortDoctype: true,
};
export default defineConfig({
plugins: [
{
name: 'minify-html',
apply: 'build',
enforce: 'post',
transformIndexHtml: {
order: 'post',
handler(html) {
return minify(html, htmlMinifyOptions);
},
},
},
],
});