{"id":42232,"library":"vite-plugin-insert-html","title":"vite-plugin-insert-html","description":"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.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/NotWoods/vite-plugin-insert-html","tags":["javascript","vite","vite-plugin","html","inject","insert","hyperscript","jsx","typescript"],"install":[{"cmd":"npm install vite-plugin-insert-html","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-insert-html","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-insert-html","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin requires Vite 4+","package":"vite","optional":false}],"imports":[{"note":"Named export, not default","wrong":"import insertHtml from 'vite-plugin-insert-html'","symbol":"insertHtml","correct":"import { insertHtml } from 'vite-plugin-insert-html'"},{"note":"ESM-only; CJS require is not supported","wrong":"const { h } = require('vite-plugin-insert-html')","symbol":"h","correct":"import { h } from 'vite-plugin-insert-html'"},{"note":"Type is from Vite core, not this plugin","wrong":"import { HtmlTagDescriptor } from 'vite-plugin-insert-html'","symbol":"HtmlTagDescriptor","correct":"import type { HtmlTagDescriptor } from 'vite'"}],"quickstart":{"code":"// vite.config.js\nimport { defineConfig } from 'vite';\nimport { insertHtml, h } from 'vite-plugin-insert-html';\n\nexport default defineConfig({\n  plugins: [\n    insertHtml({\n      head: [\n        h('meta', { charset: 'utf-8' }),\n        h('link', { rel: 'icon', href: '/favicon.ico' }),\n        h('title', {}, 'My App'),\n      ],\n      body: [\n        h('script', { src: 'https://analytics.example.com/script.js', async: true }),\n      ],\n      headPrepend: [\n        h('meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0' }),\n      ],\n      bodyPrepend: [\n        h('noscript', {}, 'JavaScript is required.'),\n      ],\n    }),\n  ],\n});","lang":"javascript","description":"Configures Vite to inject multiple HTML tags into head and body with prepend options."},"warnings":[{"fix":"Use 'headPrepend' or 'bodyPrepend' properties instead of 'head' or 'body' if you need tags before existing content.","message":"Tags are appended by default; use headPrepend/bodyPrepend to prepend","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"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).","message":"Removed CJS support; plugin is ESM-only","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Migrate to spread syntax: h('div', {class: 'foo'}, h('span'))","message":"The 'h' function signature changed from (tag, attrs, children) to (tag, attrs, ...children) in v1.0.0","severity":"deprecated","affected_versions":"<1.0.0"},{"fix":"Use true for boolean attributes like disabled, hidden. Use string 'true' if you need the literal string.","message":"Attribute value 'true' is serialized as the attribute name without a value (HTML boolean attribute)","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure any user-provided strings are sanitized to prevent XSS.","message":"Children can be an HTML string, but it will be inserted as raw HTML without escaping","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'4.0.0':49 '7':50 'altern':63 'app':44 'arbitrari':13 'array':30 'beyond':47 'bodi':20 'construct':60 'context':39 'depend':46 'descriptor':62 'dynam':32 'entri':24 'function':33 'h':58 'head':18 'heavier':65 'helper':57 'html':5,14,23,71,74,81 'hyperscript':55,84 'hyperscript-lik':54 'inject':12,82 'insert':4,83 'javascript':76 'jsx':85 'lightweight':7 'like':56,67 'manipul':75 'manual':73 'multi':42 'multi-pag':41 'page':43 'plugin':3,9,66,70,80 'point':25 'receiv':35 'ship':51 'static':28 'support':26 'tag':15,29,61 'transform':38 'typescript':86 'v1.0.3':10 'vite':2,8,36,48,69,77,79 'vite-plugin':78 'vite-plugin-html':68 'vite-plugin-insert-html':1","created_at":"2026-06-04T18:56:15.709632+00:00","updated_at":"2026-06-04T18:56:15.709632+00:00","problems":[{"fix":"Replace 'import insertHtml from ...' with 'import { insertHtml } from ...'","cause":"Using a default import instead of named import","error":"TypeError: (0 , vite_plugin_insert_html.insertHtml) is not a function"},{"fix":"Use import syntax, or configure your project for ESM (type: 'module' in package.json)","cause":"Using CommonJS require() to import an ESM-only package","error":"require() of ES Module ... not supported"},{"fix":"Update Vite to >=4.0.0, or use an older version of the plugin if you cannot upgrade Vite.","cause":"Using an older version of Vite (<4.0.0)","error":"The plugin 'vite-plugin-insert-html' requires Vite version >=4.0.0"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/NotWoods/vite-plugin-insert-html#readme","github":"https://github.com/NotWoods/vite-plugin-insert-html","docs":null,"changelog":null,"pypi":null,"npm":"vite-plugin-insert-html","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}