Skip to content

Instantly share code, notes, and snippets.

@malobre
Created March 22, 2023 23:23
Show Gist options
  • Save malobre/4eb3e281fc9dc05d4c79bb59d59c87eb to your computer and use it in GitHub Desktop.
Save malobre/4eb3e281fc9dc05d4c79bb59d59c87eb to your computer and use it in GitHub Desktop.
`html-minifier` as a vite plugin
import { minify as minifyHTML } from "html-minifier";
const vitePluginHtmlMinifier = {
name: "html-minifier",
apply: "build",
transformIndexHtml: (html) => minifyHTML(html, {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
collapseBooleanAttributes: true,
decodeEntities: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
removeAttributeQuotes: true,
removeComments: true,
removeOptionalTags: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
}),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment