Frontend - Development
Frontend Deployment
Build Configuration
Vite Production Build
The frontend uses Vite for production builds with the following optimizations:
// vite.config.ts optimizations
export default defineConfig({
build: {
target: 'ES2020',
sourcemap: true,
minify: 'esbuild',
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
ui: ['@radix-ui/**'],
}
}
}
}
})
Environment Configuration
Production environment variables:
VITE_API_URL=your_api_url
VITE_SOCKET_URL=your_websocket_url
VITE_GITHUB_CLIENT_ID=your_github_client_id
Deployment Strategies
Docker Deployment
Multi-Stage Build
# Build stage FROM node:20-alpine AS builder WORKDIR /app COPY package.json yarn.lock ./ RUN yarn install --frozen-lockfile COPY . . RUN yarn build # Production stage FROM nginx:alpine COPY --from=builder /app/dist /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf
NGINX Configuration
server { listen 80; root /usr/share/nginx/html; index index.html; location / { try_files $uri $uri/ /index.html; } # Cache static assets location /assets { expires 1y; add_header Cache-Control "public, no-transform"; } }
Static Hosting
Build Output
dist/ ├── assets/ │ ├── js/ │ ├── css/ │ └── images/ ├── index.html └── config.json
CDN Configuration
- Configure cache headers
- Enable CORS for assets
- Set up SSL/TLS
Performance Optimization
Code Splitting
Route-Based Splitting
const ProjectDetails = lazy(() => import('./pages/project')); const Settings = lazy(() => import('./pages/settings'));
Component Chunking
const ChartComponent = lazy(() => import('./components/Chart'));
Asset Optimization
Image Handling
- Use WebP format
- Implement lazy loading
- Set up responsive images
Font Loading
<link rel="preload" href="/fonts/montserrat.woff2" as="font" type="font/woff2" crossorigin />
Monitoring and Analytics
Error Tracking
Error Boundary Setup
class ErrorBoundary extends React.Component { componentDidCatch(error, errorInfo) { // Log to error tracking service } }
Performance Monitoring
- Track Core Web Vitals
- Monitor client-side errors
- Track API response times
Health Checks
API Connection
const checkHealth = async () => { try { await fetch('/health'); return true; } catch { return false; } };
WebSocket Connection
socket.on('connect_error', (error) => { // Handle connection errors });
Security Measures
CSP Configuration
add_header Content-Security-Policy "
default-src 'self';
script-src 'self' 'unsafe-inline';
style-src 'self' 'unsafe-inline' https://fonts.googleapis.com;
font-src 'self' https://fonts.gstatic.com;
img-src 'self' data: https:;
connect-src 'self' wss: https:;
";
CORS Settings
location /api {
add_header 'Access-Control-Allow-Origin' '$http_origin' always;
add_header 'Access-Control-Allow-Credentials' 'true' always;
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
}
CI/CD Integration
Build Pipeline
build_frontend:
stage: build
script:
- yarn install
- yarn build
artifacts:
paths:
- dist/
deploy_frontend:
stage: deploy
script:
- docker build -t frontend .
- docker push frontend
only:
- main
Deployment Verification
Smoke Tests
- Verify main routes
- Check API connectivity
- Test authentication flow
Rollback Procedure
- Keep previous version tagged
- Maintain configuration backups
- Document rollback steps