Skip to content

Instantly share code, notes, and snippets.

@cecilemuller
Created April 15, 2024 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cecilemuller/7a8eae6091feb05aa84b413118a1a45c to your computer and use it in GitHub Desktop.
Save cecilemuller/7a8eae6091feb05aa84b413118a1a45c to your computer and use it in GitHub Desktop.
Vite Plugin: Prettier
import type {PluginOption} from "vite";
import {format} from "prettier";
/**
* Format HTML pages using Prettier.
*/
export function prettierPlugin(): PluginOption {
return {
name: "prettier",
transformIndexHtml: {
order: "pre",
handler: async (html: string) => {
const formatted = await format(html, {parser: "html"});
return formatted;
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment