Vite plugin that transforms Pug templates into HTML using Vite's transformIndexHtml hook. Current stable version is 1.0.8. Supports Vite v2 through v7 (peer dependency: ^2.5.10 || ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0), with Node.js version requirements aligning with Vite versions. Key differentiator: uses <template> tags with data attributes in HTML entry points rather than replacing the entire HTML, allowing multiple Pug templates per page. Ships TypeScript types. Minimal configuration with optional pugOptions and pugLocals.
npm install vite-plugin-pug-transformerVerified import paths — ran on the pinned version, not inferred.
Shows basic setup with Vite config, HTML entry using template tags, and a simple Pug template.
Use <template data-type="pug" data-src="./file.pug"> in your HTML entry point. Do not use import .pug in JavaScript.
Upgrade to Vite v4 or newer. If you must use Vite v2/v3, pin plugin version to 1.0.6 or earlier (not verified).
If you need dynamic locals, implement a custom Vite plugin that rebuilds the config on env change or use process.env inside pugOptions.
This plugin is only for the main HTML entry. For Pug in JavaScript, use another loader like @rollup/plugin-pug.
Run npm install vite-plugin-pug-transformer or yarn add vite-plugin-pug-transformer.
Use import vitePugPlugin from 'vite-plugin-pug-transformer';
Only use Pug via <template> tags in HTML; do not import .pug in JS files.
Ensure <template data-type="pug" data-src="./yourfile.pug"> has a valid path to a .pug file.