# vite-plugin-index-html

> Vite Plugin that simplifies creation of HTML files to serve your bundles

Latest version **2.0.2** (published 2022-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install vite-plugin-index-html
pnpm add vite-plugin-index-html
yarn add vite-plugin-index-html
bun add vite-plugin-index-html
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-01-17 |
| First published | 2021-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 47.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | maoxiaoke@outlook.com |
| Maintainers | maoxiaoke, rax-publisher |
| Keywords | vite, vite-plugin, roll-plugin, html, template |

## Links

- npm: https://www.npmjs.com/package/vite-plugin-index-html
- npm.io page: https://npm.io/package/vite-plugin-index-html

## Dependencies (2)

- [fs-extra](https://npm.io/package/fs-extra.md) ^10.0.0
- [html-minifier-terser](https://npm.io/package/html-minifier-terser.md) ^6.0.2

## Alternatives

- [@tsparticles/shape-image](https://npm.io/package/@tsparticles/shape-image.md) — 303.7K weekly downloads
- [@tsparticles/shape-line](https://npm.io/package/@tsparticles/shape-line.md) — 233.7K weekly downloads
- [stringify-attributes](https://npm.io/package/stringify-attributes.md) — 58.6K weekly downloads
- [mobile-drag-drop](https://npm.io/package/mobile-drag-drop.md) — 46.3K weekly downloads
- [@comunica/actor-rdf-parse-html](https://npm.io/package/@comunica/actor-rdf-parse-html.md) — 29.2K weekly downloads

## Recent versions

- 2.0.2 (latest) — 2022-01-17
- 2.0.2-0 (beta) — 2022-01-06
- 2.0.1 — 2021-12-17
- 2.0.1-5 — 2021-12-17
- 2.0.1-4 — 2021-12-17
- 2.0.1-3 — 2021-12-17
- 2.0.1-2 — 2021-12-16
- 2.0.1-1 — 2021-12-16
- 2.0.1-0 — 2021-12-15
- 2.0.0 — 2021-11-29
- 2.0.0-0 — 2021-11-29
- 1.0.0 — 2021-11-11
- 0.1.3 — 2021-11-01
- 0.1.2 — 2021-10-20
- 0.1.1 — 2021-10-12

## README

# vite-plugin-index-html

快速创建 Vite 应用的 HTML 文件。功能类似于 [webpack-html-plugin](https://github.com/jantimon/html-webpack-plugin)。

## Motivation

Vite 应用默认使用根目录下的 [index.html](https://vitejs.dev/guide/#index-html-and-project-root) 作为入口文件，通过解析 `index.html` 的 `<script />` 并生成一个 “虚拟的” 脚本资源入口文件，形如：

```js
import 'polyfill';
import './src/main.ts';
```

在某些非 [LibraryMode](https://vitejs.dev/guide/build.html#library-mode)，需要明确脚本入口文件为 `./src/main.j|ts`。该插件实现了类似于 [webpack-html-plugin](https://github.com/jantimon/html-webpack-plugin) 的能力。


## Features

- [x] 修改应用入口
- [x] 支持 Minify
- [x] 支持导出入口文件签名
- [ ] 支持模板
- [ ] 支持 MPA


## 用法

### npm/yarn

```shell
npm i --save-dev vite-plugin-index-html

# or

yarn add --dev vite-plugin-index-html
```

### 使用

在 `vite.config.ts` 中引入：

```ts
import htmlPlugin from 'vite-plugin-index-html';

// vite.config.ts
export default defineConfig({
  plugins: [vue(), htmlPlugin({
    entry: './src/main.ts'
  })]
})
```

## 参数

- `entry`

应用入口，默认为 `.src/main.j|ts?x`。

- `template`

template 地址，默认为 `./src/index.html`。

- `filename`

生成的 HTML 文件名，默认为 `index.html`。

- `publicPath`

公共基础路径。默认为 [base](https://vitejs.dev/guide/build.html#public-base-path)。

- `minify`

是否压缩 html 代码。默认为 `auto`，development 下默认不压缩，production 下默认压缩。

类型：boolean | 'auto' | object

object 详细配置参考 [html-minifier-terser](https://www.npmjs.com/package/html-minifier-terser)

- `preserveEntrySignatures`

是否保留入口文件签名。

类型："strict" | "allow-extension" | "exports-only" | false

更详细介绍参考 [rollup preserveEntrySignatures](https://rollupjs.org/guide/en/#preserveentrysignatures)。

## License

MIT

---
_Source: https://npm.io/package/vite-plugin-index-html · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
