Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Last active January 28, 2025 16:21
Show Gist options
  • Save cecilemuller/fcfe7b09764ca40fa435b540e59d9a76 to your computer and use it in GitHub Desktop.
Save cecilemuller/fcfe7b09764ca40fa435b540e59d9a76 to your computer and use it in GitHub Desktop.
Vite Plugin: apply Prettier to HTML output using `transformIndexHtml`
import type { PluginOption } from "vite";
import { format } from "prettier";
export function plugin(): PluginOption {
return {
name: "example",
transformIndexHtml: async (html) => format(html, {
// https://prettier.io/docs/en/options.html
parser: "html",
htmlWhitespaceSensitivity: "ignore"
})
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment