Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/wojtekmaj/vite-plugin-simple-html. Vite plugin for HTML processing and minification
Something went wrong. Try again.
1.2 kB · 51 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152import { minify } from '@swc/html';
import type { Options as SwcHtmlOptions } from '@swc/html';import type { HtmlTagDescriptor, PluginOption } from 'vite';
type Options = { inject?: { data?: Record<string, string>; tags?: HtmlTagDescriptor[]; }; minify?: boolean | SwcHtmlOptions;};
export const defaultMinifyOptions: SwcHtmlOptions = { collapseWhitespaces: 'all', minifyCss: true, minifyJs: false, minifyJson: true, quotes: true, removeComments: true, removeEmptyAttributes: true, removeRedundantAttributes: 'all', tagOmission: false,};
export default function simpleHtmlPlugin({ minify: minifyOptions = false }: Options = {}): { name: string; transformIndexHtml: { order: 'post'; handler: (html: string) => Promise<string>; };} { return { name: 'vite:simple-html:minify', transformIndexHtml: { order: 'post', handler: async (html: string) => { let result = html;
if (minifyOptions) { ({ code: result } = await minify( result, minifyOptions === true ? defaultMinifyOptions : minifyOptions, )); }
return result; }, }, } satisfies PluginOption;}