/** * Vite plugin for gonia.js. * * @remarks * - Auto-detects directive usage in templates and injects imports * - Scans custom directive sources to build import map * - Transforms directive functions to add $inject arrays at build time * - Configures Vite for SSR with gonia.js * * @packageDocumentation */ import type { Plugin } from 'vite'; /** * Options for directive registration. */ export interface DirectiveOptionsConfig { scope?: boolean; template?: string | ((attrs: Record) => string | Promise); provide?: Record; } /** * Plugin options. */ export interface GoniaPluginOptions { /** * Automatically detect and import directives from source code. * @defaultValue true */ autoDirectives?: boolean; /** * Additional directives to include (for runtime/dynamic cases). * Use full directive names (e.g., 'g-text', 'my-component'). * @example ['g-text', 'g-for', 'app-header'] */ includeDirectives?: string[]; /** * Directives to exclude from auto-detection. * Use full directive names. */ excludeDirectives?: string[]; /** * Glob patterns for files containing custom directive definitions. * The plugin scans these files at build start to discover directive() calls. * @example ['src/directives/**\/*.ts'] */ directiveSources?: string[]; /** * Prefixes for attribute directives. * @defaultValue ['g-'] * @example ['g-', 'v-', 'x-'] */ directiveAttributePrefixes?: string[]; /** * Prefixes for element/component directives. * Defaults to directiveAttributePrefixes if not specified. * @example ['app-', 'my-', 'ui-'] */ directiveElementPrefixes?: string[]; /** * Options to apply to directives. * * Can be an object mapping directive names to options, or a function * that receives the directive name and returns options. * * @example * ```ts * // Object form - explicit per-directive * directiveOptions: { * 'g-text': { scope: true }, * 'app-card': { template: '
' } * } * * // Function form - dynamic/pattern-based * directiveOptions: (name) => name.startsWith('app-') ? { scope: true } : undefined * ``` */ directiveOptions?: Record | ((name: string) => DirectiveOptionsConfig | undefined); } /** * Gonia Vite plugin. * * @remarks * - Auto-detects directive usage and injects imports * - Scans custom directive sources to discover user directives * - Adds $inject arrays to directive functions for minification safety * - Configures Vite for SSR with gonia.js * * @example * ```ts * // vite.config.ts * import { defineConfig } from 'vite'; * import { gonia } from 'gonia/vite'; * * export default defineConfig({ * plugins: [gonia()] * }); * ``` * * @example * ```ts * // With custom directives * export default defineConfig({ * plugins: [gonia({ * directiveSources: ['src/directives/**\/*.ts'], * directiveAttributePrefixes: ['g-'], * directiveElementPrefixes: ['app-', 'ui-'], * })] * }); * ``` */ export declare function gonia(options?: GoniaPluginOptions): Plugin; export default gonia;