vite-plugin-svg-icons-ng
Version:
Vite plugin for easily creating an SVG sprite and injecting it for use, with a brand-new version.
66 lines (61 loc) • 1.74 kB
TypeScript
import { Plugin } from 'vite';
import { Config } from 'svgo';
type SvgoConfig = Omit<Config, 'path'> | false;
type InjectMode = 'body-first' | 'body-last';
type strokeOverrideConfig = boolean | {
color: string;
};
interface Options {
/**
* icons store directories
* all svg files in these will be converted to svg sprite.
*/
iconDirs: string[];
/**
* icon name format
* @default: icon-[dir]-[name]
*/
symbolId?: string;
/**
* SVGO configuration, used to optimize svg
* @default:{}
*/
svgoOptions?: SvgoConfig;
/**
* icon format
* @default: 'body-last'
*/
inject?: InjectMode;
/**
* custom dom id
* @default: '__svg__icons__dom__'
*/
customDomId?: string;
/**
* override `stroke` attribute
* `false` to disable, `true` to override as `currentColor`, or an object `{ color: '#fff' }`
* @default: false
*/
strokeOverride?: strokeOverrideConfig;
}
type SymbolEntry = {
symbolId: string;
symbol: string;
};
interface CacheEntry {
mtimeMs?: number;
entry: SymbolEntry;
}
declare function validate(opt: Options): void;
declare function createSvgIconsPlugin(userOptions: Options): Plugin;
declare function generateSymbolId(relativePath: string, options: Required<Options>): string;
declare function parseDirName(name: string): {
dirName: string;
baseName: string;
};
declare const __TEST__: {
generateSymbolId: typeof generateSymbolId;
parseDirName: typeof parseDirName;
validate: typeof validate;
};
export { type CacheEntry, type InjectMode, type Options, type SvgoConfig, type SymbolEntry, __TEST__, createSvgIconsPlugin, type strokeOverrideConfig };