vite-plugin-banner
Version:
A banner plugin for Vite. Adds a banner to the top of each generated chunk.
84 lines (80 loc) • 2.42 kB
TypeScript
import * as rollup from 'rollup';
import { ResolvedConfig } from 'vite';
/**
* Some options from `vite.config.[ts|js]`
*
* @since 0.2.0
*/
interface BannerPluginOptions {
/**
* The comment content of the banner
*
* @since ^0.6.0 support for `ContentCallback` types
*/
content: string | ContentCallback;
/**
* The output directory from the configuration of Vite.js
*
* @default viteConfig.build.outDir
* @see https://vitejs.dev/config/build-options.html#build-outdir
*/
outDir?: string;
/**
* Whether to print error messages to the console
*
* @since 0.4.0
* @default false
*/
debug?: boolean;
/**
* By default, the validity of the content will be verified.
*
* If set to `false`, no verification will be performed.
*
* @since 0.5.0
* @default true
* @see https://github.com/chengpeiquan/vite-plugin-banner/issues/13
*/
verify?: boolean;
}
/**
* Callback function to get the contents to be injected.(or not inject)
*
* @since 0.6.0
* @example
* ```ts
* content: (fileName: string) => {
* // Or use switch statement
* return fileName.endsWith('.js')
* ? 'This message will inject into `js` files.'
* : 'This message will inject into other files.'
* }
* ```
*
* @param fileName - The name of the file currently being processed
* @returns
*
* 1. When a valid string is returned, it will become the banner content
* 2. Returning a Falsy value will skip processing(e.g. `''`, `null`, `undefined`)
*/
type ContentCallback = (fileName: string) => string | null | undefined;
type UnionPluginOptions = string | BannerPluginOptions | ContentCallback;
/** Configuration of the plugin's internal runtime */
interface PluginConfig {
content: string | ContentCallback;
outDir: string;
debug: boolean;
verify: boolean;
}
/**
* Add banner comments to files
*
* @param pluginOptions - A comment content or An option
*/
declare function export_default(pluginOptions: UnionPluginOptions): {
name: string;
apply: "build";
configResolved(this: void, resolvedConfig: ResolvedConfig): void;
writeBundle(this: rollup.PluginContext, _: rollup.NormalizedOutputOptions, bundle: rollup.OutputBundle): Promise<void>;
};
export { type BannerPluginOptions, type ContentCallback, type PluginConfig, export_default as default };