{"id":13417347,"url":"https://github.com/vbenjs/vite-plugin-html","last_synced_at":"2025-05-15T00:09:37.415Z","repository":{"id":39449427,"uuid":"307595086","full_name":"vbenjs/vite-plugin-html","owner":"vbenjs","description":"A vite plugin for processing html. It is developed based on lodash template","archived":false,"fork":false,"pushed_at":"2024-08-07T03:51:14.000Z","size":504,"stargazers_count":651,"open_issues_count":91,"forks_count":99,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-05-11T12:08:08.031Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vbenjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-10-27T05:32:11.000Z","updated_at":"2025-05-10T16:08:26.000Z","dependencies_parsed_at":"2023-02-01T04:00:47.061Z","dependency_job_id":"de2d05fb-c547-40bd-b7a8-61da29e0631c","html_url":"https://github.com/vbenjs/vite-plugin-html","commit_stats":{"total_commits":78,"total_committers":15,"mean_commits":5.2,"dds":0.3076923076923077,"last_synced_commit":"4a32df2b416b161663904de51530f462a6219fd5"},"previous_names":["anncwb/vite-plugin-html"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-html","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-html/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-html/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vbenjs%2Fvite-plugin-html/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vbenjs","download_url":"https://codeload.github.com/vbenjs/vite-plugin-html/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254249206,"owners_count":22039029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T22:00:35.610Z","updated_at":"2025-05-15T00:09:32.372Z","avatar_url":"https://github.com/vbenjs.png","language":"TypeScript","readme":"# vite-plugin-html\n\n**English** | [中文](./README.zh_CN.md)\n\n## Features\n\n- HTML compression capability\n- EJS template capability\n- Multi-page application support\n- Support custom `entry`\n- Support custom `template`\n\n## Install (yarn or npm)\n\n**node version:** \u003e=12.0.0\n\n**vite version:** \u003e=2.0.0\n\n```bash\nyarn add vite-plugin-html -D\n```\n\n或\n\n```bash\nnpm i vite-plugin-html -D\n```\n\n## Usage\n\n- Add EJS tags to `index.html`, e.g.\n\n```html\n\u003chead\u003e\n  \u003cmeta charset=\"UTF-8\" /\u003e\n  \u003clink rel=\"icon\" href=\"/favicon.ico\" /\u003e\n  \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n  \u003ctitle\u003e\u003c%- title %\u003e\u003c/title\u003e\n  \u003c%- injectScript %\u003e\n\u003c/head\u003e\n```\n\n- Configure in `vite.config.ts`, this method can introduce the required functions as needed\n\n```ts\nimport { defineConfig, Plugin } from 'vite'\nimport vue from '@vitejs/plugin-vue'\n\nimport { createHtmlPlugin } from 'vite-plugin-html'\n\nexport default defineConfig({\n  plugins: [\n    vue(),\n    createHtmlPlugin({\n      minify: true,\n      /**\n       * After writing entry here, you will not need to add script tags in `index.html`, the original tags need to be deleted\n       * @default src/main.ts\n       */\n      entry: 'src/main.ts',\n      /**\n       * If you want to store `index.html` in the specified folder, you can modify it, otherwise no configuration is required\n       * @default index.html\n       */\n      template: 'public/index.html',\n\n      /**\n       * Data that needs to be injected into the index.html ejs template\n       */\n      inject: {\n        data: {\n          title: 'index',\n          injectScript: `\u003cscript src=\"./inject.js\"\u003e\u003c/script\u003e`,\n        },\n        tags: [\n          {\n            injectTo: 'body-prepend',\n            tag: 'div',\n            attrs: {\n              id: 'tag',\n            },\n          },\n        ],\n      },\n    }),\n  ],\n})\n```\n\nMulti-page application configuration\n\n```ts\nimport { defineConfig } from 'vite'\nimport { createHtmlPlugin } from 'vite-plugin-html'\n\nexport default defineConfig({\n  plugins: [\n    createHtmlPlugin({\n      minify: true,\n      pages: [\n        {\n          entry: 'src/main.ts',\n          filename: 'index.html',\n          template: 'public/index.html',\n          injectOptions: {\n            data: {\n              title: 'index',\n              injectScript: `\u003cscript src=\"./inject.js\"\u003e\u003c/script\u003e`,\n            },\n            tags: [\n              {\n                injectTo: 'body-prepend',\n                tag: 'div',\n                attrs: {\n                  id: 'tag1',\n                },\n              },\n            ],\n          },\n        },\n        {\n          entry: 'src/other-main.ts',\n          filename: 'other.html',\n          template: 'public/other.html',\n          injectOptions: {\n            data: {\n              title: 'other page',\n              injectScript: `\u003cscript src=\"./inject.js\"\u003e\u003c/script\u003e`,\n            },\n            tags: [\n              {\n                injectTo: 'body-prepend',\n                tag: 'div',\n                attrs: {\n                  id: 'tag2',\n                },\n              },\n            ],\n          },\n        },\n      ],\n    }),\n  ],\n})\n```\n\n## Parameter Description\n\n`createHtmlPlugin(options: UserOptions)`\n\n### UserOptions\n\n| Parameter | Types                    | Default       | Description                                       |\n| --------- | ------------------------ | ------------- | ------------------------------------------------- |\n| entry     | `string`                 | `src/main.ts` | entry file path                                   |\n| template  | `string`                 | `index.html`  | relative path to the template                     |\n| inject    | `InjectOptions`          | -             | Data injected into HTML                           |\n| minify    | `boolean｜MinifyOptions` | -             | whether to compress html                          |\n| pages     | `PageOption`             | -             | Multi-page configuration                          |\n\n### InjectOptions\n\n| Parameter  | Types                 | Default | Description                                                               |\n| ---------- | --------------------- | ------- | ------------------------------------------------------------------------- |\n| data       | `Record\u003cstring, any\u003e` | -       | injected data                                                             |\n| ejsOptions | `EJSOptions`          | -       | ejs configuration Options[EJSOptions](https://github.com/mde/ejs#options) |\n| tags       | `HtmlTagDescriptor`   | -       | List of tags to inject                                                    |\n\n`data` can be accessed in `html` using the `ejs` template syntax\n\n#### Env inject\n\nBy default, the contents of the `.env` file will be injected into index.html, similar to vite's `loadEnv` function\n\n### PageOption\n\n| Parameter     | Types           | Default       | Description                   |\n| ------------- | --------------- | ------------- | ----------------------------- |\n| filename      | `string`        | -             | html file name                |\n| template      | `string`        | `index.html`  | relative path to the template |\n| entry         | `string`        | `src/main.ts` | entry file path               |\n| injectOptions | `InjectOptions` | -             | Data injected into HTML       |\n\n### MinifyOptions\n\nDefault compression configuration\n\n```ts\n    collapseWhitespace: true,\n    keepClosingSlash: true,\n    removeComments: true,\n    removeRedundantAttributes: true,\n    removeScriptTypeAttributes: true,\n    removeStyleLinkTypeAttributes: true,\n    useShortDoctype: true,\n    minifyCSS: true,\n```\n\n### Run the playground\n\n```bash\npnpm install\n\n# spa\ncd ./packages/playground/basic\n\npnpm run dev\n\n# map\ncd ./packages/playground/mpa\n\npnpm run dev\n\n```\n\n## Example project\n\n[Vben Admin](https://github.com/anncwb/vue-vben-admin)\n\n## License\n\nMIT\n\n[npm-img]: https://img.shields.io/npm/v/vite-plugin-html.svg\n[npm-url]: https://npmjs.com/package/vite-plugin-html\n[node-img]: https://img.shields.io/node/v/vite-plugin-html.svg\n[node-url]: https://nodejs.org/en/about/releases/\n","funding_links":[],"categories":["Plugins","TypeScript","others"],"sub_categories":["Framework-agnostic Plugins"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvbenjs%2Fvite-plugin-html","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvbenjs%2Fvite-plugin-html","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvbenjs%2Fvite-plugin-html/lists"}