A Vite plugin (v2.0.2) for injecting HTML tags (meta, link, script, style) into the index.html at build time. It uses Vite's transformIndexHtml hook and supports configurable head/body scripts with both string and object-based attributes. Unlike raw transformIndexHtml hooks, it provides a declarative, environment-aware API for conditionally adding tags. Requires Vite >=5.0.0. Currently in active development with support for Vite 3–5.
npm install vite-plugin-html-configVerified import paths — ran on the pinned version, not inferred.
Demonstrates minimal configuration with all supported HTML injection options: title, favicon, metas, links, head/body scripts, and inline style.
Upgrade to Vite >=5.0.0 or use v1.x for older Vite (v2/v3).
Migrate to explicit meta/link tags for title and favicon to avoid removal.
Use 'preHeadScripts' for scripts that must run before other head scripts (e.g., polyfills), 'headScripts' for general head scripts, 'scripts' for body-end scripts.
For external scripts, use { src: 'url' } object; for inline code, use a string or { content: 'code' }.Use 'typeof htmlPlugin extends (opts: infer T) => any ? T : never' or inspect the .d.ts file in node_modules.
Run: npm install vite-plugin-html-config -D (or yarn/pnpm equivalent).
Upgrade Vite to >=5.0.0, or downgrade plugin to v1.x (npm install vite-plugin-html-config@1).
Change import to: import htmlPlugin from 'vite-plugin-html-config' (default import).
Use ESM syntax: import htmlPlugin from 'vite-plugin-html-config'. If your config is CJS, rename to .mjs or set type: module in package.json.