Vite plugin that formats output files with Prettier after bundle generation, specifically useful for library mode builds. Version 1.0.0 (initial release) requires Node.js >=18.0.0 || >=20.0.0 and Prettier >=3.0.0 as a peer dependency. It hooks into the closeBundle phase, finds all files in outDir, reads, formats with Prettier using the project's config, and writes back. Unlike other formatting plugins, this one ensures consistent formatting of distribution files during the build process.
npm install vite-plugin-prettier-formatVerified import paths — ran on the pinned version, not inferred.
Minimal Vite config integrating the Prettier format plugin to automatically format output files after build.
Use prettierFormat() in the plugins array.
Use only for production builds; for development, rely on editor formatting or a separate Prettier watch command.
The plugin does nothing during vite dev; ensure it's not required for development.
Update Prettier to v3 or later: npm install prettier@latest --save-dev
If needed, manually filter files or use Prettier's API with ignore support; plugin may skip based on resolveConfig
Use: import prettierFormat from 'vite-plugin-prettier-format'
Change to ESM import or set type: 'module' in package.json.
Run: npm install --save-dev prettier@^3.0.0