@wp-forge/vite-plugin
Version:
Vite plugin for WordPress theme development with WP-Forge
357 lines (343 loc) • 7.86 kB
TypeScript
import { Plugin } from 'vite';
/**
* WP-Forge Plugin Options
*/
interface WpForgePluginOptions {
/**
* Block discovery and registration options
*/
blocks?: BlockOptions;
/**
* Asset manifest generation options
*/
manifest?: ManifestOptions;
/**
* PHP hot module replacement options
*/
phpHmr?: PhpHmrOptions;
/**
* Asset handling options
*/
assets?: AssetOptions;
/**
* Design system integration options
*/
designSystem?: DesignSystemOptions;
/**
* Performance optimization options
*/
performance?: PerformanceOptions;
}
/**
* Block Options
*/
interface BlockOptions {
/**
* Directory to search for blocks
* @default 'src/blocks'
*/
dir?: string;
/**
* Auto-register blocks in WordPress
* @default true
*/
autoRegister?: boolean;
/**
* Block namespace
* @default 'wp-forge'
*/
namespace?: string;
/**
* Pattern to match block directories
* @default '* /block.json'
*/
pattern?: string;
}
/**
* Manifest Options
*/
interface ManifestOptions {
/**
* Enable manifest generation
* @default true
*/
enabled?: boolean;
/**
* Output path for manifest
* @default 'dist/.vite/manifest.json'
*/
output?: string;
/**
* Include WordPress-specific metadata
* @default true
*/
wordpress?: boolean;
}
/**
* PHP HMR Options
*/
interface PhpHmrOptions {
/**
* Enable PHP file watching
* @default true
*/
enabled?: boolean;
/**
* File patterns to watch
* @default ['** /*.php', 'theme.json']
*/
watch?: string[];
/**
* Debounce delay in ms
* @default 100
*/
debounce?: number;
}
/**
* Asset Options
*/
interface AssetOptions {
/**
* Public directory for assets
* @default 'dist'
*/
publicDir?: string;
/**
* WordPress assets URL
*/
baseUrl?: string;
}
/**
* Block Metadata (from block.json)
*/
interface BlockMetadata {
apiVersion?: number;
name: string;
title: string;
category: string;
icon?: string;
description?: string;
keywords?: string[];
attributes?: Record<string, unknown>;
supports?: Record<string, unknown>;
editorScript?: string;
editorStyle?: string;
script?: string;
style?: string;
render?: string;
}
/**
* WordPress Asset Manifest Entry
*/
interface ManifestEntry {
file: string;
src?: string;
isEntry?: boolean;
css?: string[];
assets?: string[];
dependencies?: string[];
version?: string;
}
/**
* WordPress Asset Manifest
*/
interface WordPressManifest {
[key: string]: ManifestEntry;
}
/**
* Design System Options
*/
interface DesignSystemOptions {
/**
* Enable design system integration
* @default false
*/
enabled?: boolean;
/**
* CSS framework to use
* @default 'none'
*/
framework?: 'none' | 'tailwind' | 'unocss';
/**
* Path to framework config file
*/
configPath?: string;
/**
* Enable WordPress preset integration
* Maps theme.json values to framework
* @default true
*/
wordpressPresets?: boolean;
/**
* Custom theme configuration
*/
theme?: Record<string, unknown>;
}
/**
* Performance Options
*/
interface PerformanceOptions {
/**
* Critical CSS extraction options
* @default true
*/
criticalCSS?: boolean | CriticalCSSOptions;
/**
* Lazy loading options
* @default true
*/
lazyLoading?: boolean | LazyLoadingOptions;
/**
* Asset preloading options
* @default true
*/
preload?: boolean | PreloadOptions;
}
/**
* Critical CSS Options
*/
interface CriticalCSSOptions {
/**
* Enable critical CSS extraction
* @default true
*/
enabled?: boolean;
/**
* Templates to process (without .html extension)
* @default ['index', 'single', 'page', 'archive']
*/
templates?: string[];
/**
* Viewport dimensions for extraction
* @default { width: 1300, height: 900 }
*/
dimensions?: {
width: number;
height: number;
};
/**
* Inline critical CSS in HTML
* @default true
*/
inline?: boolean;
/**
* Output path for critical CSS files
* @default 'dist/critical'
*/
output?: string;
/**
* Minimum size in bytes to extract
* @default 0
*/
minSize?: number;
}
/**
* Lazy Loading Options
*/
interface LazyLoadingOptions {
/**
* Enable lazy loading
* @default true
*/
enabled?: boolean;
/**
* Image lazy loading strategy
* @default 'native'
*/
images?: 'native' | 'intersection-observer' | 'none';
/**
* Enable CSS lazy loading
* @default true
*/
css?: boolean;
/**
* Enable chunk lazy loading
* @default true
*/
chunks?: boolean;
/**
* Placeholder type for images
* @default 'none'
*/
placeholder?: 'blur' | 'color' | 'none';
}
/**
* Preload Options
*/
interface PreloadOptions {
/**
* Enable asset preloading
* @default true
*/
enabled?: boolean;
/**
* Asset types to preload
* @default ['fonts', 'critical-css']
*/
assets?: Array<'fonts' | 'critical-css' | 'critical-js' | 'images'>;
/**
* Preload strategy
* @default 'link-tag'
*/
strategy?: 'link-tag' | 'http2-push';
}
/**
* Auto-discover and register WordPress blocks
*/
declare function wpForgeBlocks(options?: BlockOptions): Plugin;
/**
* Generate WordPress-compatible asset manifest
*
* This manifest helps WordPress properly enqueue Vite-built assets
* with correct dependencies, versions, and URLs.
*/
declare function wpForgeManifest(options?: ManifestOptions): Plugin;
/**
* Watch PHP files and trigger HMR
*
* This allows developers to see changes to PHP templates and theme files
* without manually refreshing the browser.
*/
declare function wpForgePhpHmr(options?: PhpHmrOptions): Plugin;
/**
* WordPress-compatible asset handling
*
* Ensures assets are output in WordPress-friendly structure
* and can be properly enqueued by WordPress.
*/
declare function wpForgeAssets(options?: AssetOptions): Plugin;
/**
* Design System Integration Plugin
*
* Integrates Tailwind CSS or UnoCSS with WordPress themes
*/
declare function wpForgeDesignSystem(options?: DesignSystemOptions): Plugin;
/**
* Performance Orchestrator
*
* Combines all performance plugins with unified configuration
*/
declare function wpForgePerformance(options?: PerformanceOptions): Plugin[];
/**
* WordPress-aware Tailwind CSS Preset
*
* Maps WordPress theme.json values to Tailwind configuration
*/
declare const wpForgeTailwindPreset: Partial<any>;
/**
* WordPress-aware UnoCSS Preset
*
* Maps WordPress theme.json values to UnoCSS configuration
*/
declare const wpForgeUnoPreset: any;
/**
* WP-Forge Vite Plugin
*
* Provides WordPress-specific build optimizations and development features:
* - Block auto-discovery and registration
* - Asset manifest generation for WordPress
* - PHP file watching with HMR
* - WordPress-compatible asset URLs
*/
declare function wpForge(options?: WpForgePluginOptions): Plugin[];
export { type AssetOptions, type BlockMetadata, type BlockOptions, type CriticalCSSOptions, type DesignSystemOptions, type LazyLoadingOptions, type ManifestEntry, type ManifestOptions, type PerformanceOptions, type PhpHmrOptions, type PreloadOptions, type WordPressManifest, type WpForgePluginOptions, wpForge, wpForgeAssets, wpForgeBlocks, wpForgeDesignSystem, wpForgeManifest, wpForgePerformance, wpForgePhpHmr, wpForgeTailwindPreset, wpForgeUnoPreset };