Registry / devops / vite-plugin-index-html

vite-plugin-index-html

JSON →
library2.0.2jsnpmunverified

Vite plugin that simplifies creation of HTML files as entry points for Vite builds, similar to webpack's html-webpack-plugin. Version 2.0.2 is the latest stable release, with monthly releases. It allows developers to explicitly set script entry files (e.g., ./src/main.ts) without relying on Vite's default index.html parsing. Supports minification via html-minifier-terser, custom templates, and entry signature preservation for Rollup. Unlike Vite's default index.html approach, it provides explicit control over the entry file and output HTML filename, making it suitable for non-library mode builds.

npm install vite-plugin-index-html
INSTALL
IMPORT
SIG · VITE-PLUGIN-INDEX-
V
vite-plugin-index-html
devopsjavascriptv2.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

default export
✓ import htmlPlugin from 'vite-plugin-index-html'
✗ const htmlPlugin = require('vite-plugin-index-html')
Default ESM import; no named export. CJS require may work but is not guaranteed.
options type
✓ import type { Options } from 'vite-plugin-index-html'
✗ import { Options } from 'vite-plugin-index-html'
TypeScript users should import the type as a type-only import to avoid runtime side effects.
named export (does not exist)
✓ import htmlPlugin from 'vite-plugin-index-html'
✗ import { htmlPlugin } from 'vite-plugin-index-html'
The package has only a default export; named imports will result in undefined.

Shows how to configure the plugin with common options: custom entry, template, output filename, minification, and entry signature preservation.

// vite.config.ts import { defineConfig } from 'vite'; import vue from '@vitejs/plugin-vue'; import htmlPlugin from 'vite-plugin-index-html'; export default defineConfig({ plugins: [ vue(), htmlPlugin({ entry: './src/main.ts', template: './public/index.html', filename: 'app.html', minify: true, preserveEntrySignatures: 'strict', }), ], });
Debug
Known issues
breakingThe default entry path changed from './src/main.ts' to './src/main.j|ts?x' in v2.0.0. If you rely on the old default, specify entry explicitly.
fix
Set entry: './src/main.ts' in plugin options.
affects: >=2.0.0
breakingNode.js <14 is no longer supported as of v2.0.0.
fix
Upgrade Node.js to >=14.
affects: >=2.0.0
deprecatedThe 'publicPath' option is deprecated in favor of Vite's 'base' config. It will be removed in a future major version.
fix
Use Vite's 'base' option instead of 'publicPath'.
affects: >=2.0.0
gotchaThe plugin does not work in Vite's library mode. If you use build.lib, disable this plugin.
fix
Conditionally add the plugin only when build.lib is not defined.
affects: >=1.0.0
gotchaWhen using TypeScript, ensure the options object has correct types. Pass 'minify' as an object (html-minifier-terser options) only if you know the keys.
fix
Use type assertion or import the Options type for proper type checking.
affects: >=1.0.0
Errors
Common errors & fixes
Error: The "entry" option must be a string or an array of strings, but got undefined.
The entry option was not provided or is undefined.
fix
Pass a valid entry path, e.g., 'entry: "./src/main.ts"'.
TypeError: htmlPlugin is not a function
Using named import instead of default import.
fix
Use 'import htmlPlugin from 'vite-plugin-index-html'' (default import).
[vite] Internal server error: ENOENT: no such file or directory, open '.../index.html'
The template file path is incorrect or the file does not exist.
fix
Verify the 'template' option points to an existing HTML file, or omit it to use the default.
Upgrade
Version history
2.0.2latest on npm
Audit
Dependencies
html-minifier-terseroptionalUsed for HTML minification when minify option is enabled
Agent activity
4 hits · last 30 days
node
4
Resources
vite-plugin-index-html — npm install vite-plugin-index-html · libregistry