A lightweight Vite plugin (v1.0.3) for injecting arbitrary HTML tags into the head or body of all HTML entry points. Supports both static tag arrays and dynamic functions that receive Vite's transform context for multi-page apps. No dependencies beyond Vite (>=4.0.0 <7). Ships with a hyperscript-like helper `h` for constructing tag descriptors. Alternative to heavier plugins like vite-plugin-html or manual HTML manipulation.
npm install vite-plugin-insert-htmlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Configures Vite to inject multiple HTML tags into head and body with prepend options.
Use 'headPrepend' or 'bodyPrepend' properties instead of 'head' or 'body' if you need tags before existing content.
Use ESM imports (import { insertHtml } from 'vite-plugin-insert-html') and ensure your project is configured for ESM (e.g., type: 'module' in package.json).Migrate to spread syntax: h('div', {class: 'foo'}, h('span'))Use true for boolean attributes like disabled, hidden. Use string 'true' if you need the literal string.
Ensure any user-provided strings are sanitized to prevent XSS.
Replace 'import insertHtml from ...' with 'import { insertHtml } from ...'Use import syntax, or configure your project for ESM (type: 'module' in package.json)
Update Vite to >=4.0.0, or use an older version of the plugin if you cannot upgrade Vite.