Registry / web-framework / vite-plugin-html

vite-plugin-html

JSON →
library3.2.2jsnpmunverified

Vite plugin for minifying HTML and executing lodash.template syntax in index.html. Current version 3.2.2 works with Vite 2.0+. It allows dynamic HTML content via template placeholders, CSS/JS injection, and HTML minification. Unlike alternative HTML plugins (e.g., vite-plugin-html-minifier), it provides full lodash.template support. The plugin ships TypeScript types. Release cadence is irregular; breaking changes may occur between major versions.

npm install vite-plugin-html
INSTALL
IMPORT
SIG · VITE-PLUGIN-HTML
V
vite-plugin-html
web-frameworkjavascriptv3.2.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

vitePluginHtml
import { vitePluginHtml } from 'vite-plugin-html'
const vitePluginHtml = require('vite-plugin-html')
ESM-only; CommonJS require fails. Named export (not default).
createHtmlPlugin
import { createHtmlPlugin } from 'vite-plugin-html'
import createHtmlPlugin from 'vite-plugin-html'
Function is exported as a named export. Default import is a different shape.
vitePluginHtml (default)
import vitePluginHtml from 'vite-plugin-html'
const { vitePluginHtml } = require('vite-plugin-html')
Deprecated in v3. Use named import createHtmlPlugin. Default export may be removed in future.

Basic Vite config using createHtmlPlugin to minify HTML and inject data via lodash.template.

import { defineConfig } from 'vite'; import { createHtmlPlugin } from 'vite-plugin-html'; export default defineConfig({ plugins: [ createHtmlPlugin({ minify: true, template: 'index.html', inject: { data: { title: 'My App', injectScript: '<script src="/inject.js"></script>', }, }, }), ], });
Debug
Known issues
breakingv3: default export renamed to createHtmlPlugin; vitePluginHtml deprecated.
fix
Use import { createHtmlPlugin } from 'vite-plugin-html' instead.
affects: >=3.0.0
breakingv2: changed plugin options shape; some options now nested under 'inject'.
fix
Review docs for v2 option changes; migrate inject scripts to 'inject' object.
affects: >=2.0.0 <3.0.0
deprecatedv3 deprecated default export; will be removed in v4.
fix
Switch to named export createHtmlPlugin.
affects: >=3.0.0
gotchaPlugin only processes index.html; other HTML files not affected.
fix
Use separate plugins or custom logic for multiple HTML files.
affects: >=1.0.0
gotchalodash.template syntax can be slow for large inject data; consider limiting.
fix
Preprocess data outside plugin or use simpler templating.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , vite_plugin_html_1.default) is not a function
Using default import in v3; default export is deprecated and may be undefined.
fix
Change import to: import { createHtmlPlugin } from 'vite-plugin-html'
Error: Cannot find module 'vite-plugin-html'
Package not installed or wrong version.
fix
Run: npm install vite-plugin-html --save-dev
ERR_REQUIRE_ESM from CJS require()
Using require() on an ESM-only package.
fix
Use import() or set type: 'module' in package.json.
Upgrade
Version history
3.2.2latest on npm
Audit
Dependencies
viteoptionalpeer dependency; plugin only works with Vite >=2.0.0
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vite-plugin-html — npm install vite-plugin-html · libregistry