slideshare/VITE_PERFORMANCE.md
Michael Mainguy 15d3789bb4 Add full-screen layout preview route and fix iframe sandbox issue
- Create LayoutPreviewPage component for full-screen layout previews
- Add preview route /themes/:themeId/layouts/:layoutId/preview to App routing
- Update theme components with preview links and improved navigation
- Fix iframe sandbox error by adding allow-scripts permission
- Enhance template renderer with layout metadata support
- Replace PostCSS with regex-only CSS parsing for browser compatibility
- Add comprehensive standards documentation for code quality
- Clean up CSS slot indicators to be always visible with descriptions

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-20 13:48:13 -05:00

131 lines
3.6 KiB
Markdown

# Vite Performance Standards
## Missing Configuration
The current `vite.config.ts` is missing critical performance optimizations.
## Required Vite Configuration Updates
### 1. Resolve Extensions (CRITICAL)
```typescript
// ADD to vite.config.ts
export default defineConfig({
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.json']
}
});
```
**Impact**: Faster module resolution, explicit extension requirements
### 2. Server Warmup (HIGH IMPACT)
```typescript
// ADD to vite.config.ts
export default defineConfig({
server: {
warmup: {
clientFiles: [
'./src/components/**/*.tsx',
'./src/utils/**/*.ts',
'./src/types/**/*.ts',
'./src/themes/**/*.ts'
]
}
}
});
```
**Impact**: Faster initial load times, better dev experience
### 3. Build Optimizations
```typescript
// ADD to vite.config.ts
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
router: ['react-router-dom'],
themes: ['./src/utils/themeLoader', './src/utils/cssParser']
}
}
}
}
});
```
**Impact**: Better code splitting, improved cache utilization
### 4. Dependency Pre-bundling
```typescript
// ADD to vite.config.ts
export default defineConfig({
optimizeDeps: {
include: ['react', 'react-dom', 'react-router-dom'],
exclude: ['@vite/client', '@vite/env']
}
});
```
**Impact**: Faster cold starts, consistent dependency handling
## Current Performance Issues
### 1. Barrel File Usage
**Problem**: Two barrel files present
- `src/components/themes/index.ts`
- `src/themes/index.ts`
**Impact**: Prevents tree-shaking, slower builds
**Solution**: Remove barrel files, use direct imports
### 2. Missing File Extensions
**Problem**: Import statements lack explicit extensions
```typescript
// ❌ CURRENT
import App from './App.tsx'
import { getThemes } from '../../themes'
// ✅ SHOULD BE
import App from './App.tsx'
import { getThemes } from '../../themes/index.ts'
```
### 3. No Warmup Configuration
**Problem**: Cold start performance is suboptimal
**Solution**: Configure server warmup for frequently accessed files
## Implementation Priority
### IMMEDIATE (Critical Performance Impact)
1. **Remove barrel file imports** - Replace with direct imports
2. **Add resolve extensions** - Configure explicit extension handling
3. **Configure server warmup** - Improve dev server startup
### SHORT TERM (Build Performance)
1. **Add manual chunk configuration** - Optimize bundle splitting
2. **Configure dependency pre-bundling** - Improve cold start times
3. **Add explicit file extensions** - All import statements
### LONG TERM (Advanced Optimizations)
1. **Dynamic imports for themes** - Code splitting for theme system
2. **Service worker integration** - Cache theme assets
3. **Module federation** - If theme system becomes shared
## Monitoring Standards
- **Bundle size analysis**: Use `npm run build -- --analyze`
- **Dev server startup time**: Should be < 1 second after warmup
- **Hot reload performance**: Changes should reflect in < 200ms
- **Build time targets**: Production build < 30 seconds
## File Size Targets
- **Main bundle**: < 200KB gzipped
- **Theme chunks**: < 50KB each
- **CSS bundles**: < 100KB total
- **Asset optimization**: Images < 500KB each
## Implementation Checklist
- [ ] Remove barrel file exports
- [ ] Add resolve extensions configuration
- [ ] Configure server warmup paths
- [ ] Add manual chunk configuration
- [ ] Configure dependency pre-bundling
- [ ] Add explicit import extensions
- [ ] Set up bundle analysis
- [ ] Monitor performance metrics