vite-plugin-generate-html
Version:
A Vite plugin to generate separate output files for JavaScript and CSS bundles with customizable attributes.
58 lines (57 loc) • 1.68 kB
TypeScript
import type { Plugin } from "rollup";
interface VitePluginGenerateHtmlOptions {
/**
* Directory to serve as plain static assets.
* @default "/dist/"
*/
publicDir?: string;
/**
* The file to write the generated `<script>` HTML to.
*/
jsEntryFile: string;
/**
* The file to write the generated `<link>` HTML to.
*/
cssEntryFile: string;
/**
* Custom attributes for `<script>` and `<link>` elements for specific entry points.
* Entry point names must match those defined in your Vite configuration.
*
* If `output` is used, all entry points must be defined unless filtered using the `chunks` parameter.
* Default attributes:
* - `<script>`: `['type="module"']`
* - `<link>`: `['media="all"']`
*
* @default []
* @example
* output: [
* {
* main: {
* attrs: ['type="module"', 'data-foo="bar"'],
* linkAttrs: ['media="all"']
* }
* }
* ]
*/
output?: Array<Record<string, {
/**
* Attributes for the generated `<script>` element.
*/
attrs: string[];
/**
* Attributes for the generated `<link>` element.
*/
linkAttrs: string[];
}>>;
/**
* Limit the plugin to handle only specific entry points.
* By default, all entry points are handled.
*
* @default []
* @example
* chunks: ["app", "otherEntry"]
*/
chunks?: string[];
}
declare function generateHtmlFiles({ publicDir, jsEntryFile, cssEntryFile, output, chunks, }: VitePluginGenerateHtmlOptions): Plugin;
export default generateHtmlFiles;