Add HTML minification to Vite
This commit is contained in:
@@ -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);
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
Reference in New Issue
Block a user