Vite plugin for generating HTML entry files from templates, similar to html-webpack-plugin for webpack. Version 1.2.2 provides EJS/lodash.template syntax support, multi-page application (MPA) configuration via pagesDir and pages options, and works seamlessly with vite-plugin-mpa. It eliminates the need for manual index.html files per entry by virtualizing HTML. Ideal for migrating from webpack or using Vue CLI-like pages configuration in Vite projects. Ships TypeScript types and is actively maintained.
npm install vite-plugin-html-templateVerified import paths — ran on the pinned version, not inferred.
Shows MPA configuration with two pages and custom template data, using TypeScript in vite.config.ts.
Update vite.config.ts to provide a 'pages' object; see README options.
Switch to EJS syntax in HTML templates: use <%= title %> instead of {{ title }}.Verify template paths are correct relative to project root, and that files exist.
Place htmlTemplate after other HTML-modifying plugins in the plugins array.
Ensure public/index.html exists or provide custom template path in options.
Define at least one page with 'template' and 'title' keys. Example: pages: { main: { template: './index.html', title: 'App' } }Pass missing variables via 'data' option: data: { title: 'My Page' }