- Remove iframe previews from theme detail and layout detail pages for cleaner UI - Replace with informative layout cards showing descriptions and slot type badges - Fix theme hot reload by switching from custom HMR to full page reload - Update template renderer to use slot names as demo content - Add SVG pattern generation for image slots with grid background and slot labels - Improve demo content for all slot types (code, lists, tables, etc.) - Clean up HMR listeners and simplify theme change detection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
53 lines
1.7 KiB
TypeScript
53 lines
1.7 KiB
TypeScript
import type { Plugin } from 'vite';
|
|
|
|
/**
|
|
* Vite plugin to watch theme files in public directory and trigger HMR
|
|
*/
|
|
export function themeWatcherPlugin(): Plugin {
|
|
return {
|
|
name: 'theme-watcher',
|
|
async configureServer(server) {
|
|
// Dynamic imports for Node.js modules in server context
|
|
const fs = await import('fs');
|
|
const path = await import('path');
|
|
|
|
const publicThemesPath = path.resolve(process.cwd(), 'public/themes');
|
|
|
|
// Watch for changes in the themes directory
|
|
const watcher = fs.watch(
|
|
publicThemesPath,
|
|
{ recursive: true },
|
|
(eventType: string, filename: string | null) => {
|
|
if (filename && (filename.endsWith('.css') || filename.endsWith('.html'))) {
|
|
console.log(`Theme file changed: ${filename}`);
|
|
|
|
// For theme files, we need a full reload since they affect:
|
|
// - Dynamically loaded CSS files
|
|
// - Theme manifest caching
|
|
// - Layout template caching
|
|
// - CSS variables that might be applied globally
|
|
|
|
// Send full reload command to browser
|
|
server.ws.send({
|
|
type: 'full-reload'
|
|
});
|
|
|
|
// Also invalidate theme cache for good measure
|
|
const moduleId = '/src/utils/themeLoader.ts';
|
|
const module = server.moduleGraph.getModuleById(moduleId);
|
|
if (module) {
|
|
server.reloadModule(module);
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
// Cleanup watcher on server close
|
|
server.httpServer?.on('close', () => {
|
|
if (typeof watcher === 'object' && 'close' in watcher) {
|
|
watcher.close();
|
|
}
|
|
});
|
|
}
|
|
};
|
|
} |