Files
ServerKit/frontend/vite.config.js
T
Juan DenisandClaude Opus 4.8 e24f834ada refactor(frontend): Phase 2 — remove Tailwind, standardize on the SCSS design system
Per docs/plans/FRONTEND_UX_TAILWIND_CLEANUP_PLAN.md Phase 2. Removes the Tailwind
CSS v4 dependency entirely; the internal SCSS design system is now the single
styling source (aligns with AGENTS.md / project policy).

Build wiring:
- Remove @tailwindcss/vite plugin from vite.config.js.
- Drop tailwindcss, @tailwindcss/vite, tailwind-merge, tailwindcss-animate from
  package.json (+ lockfile).
- Delete src/globals.css and its import in main.jsx. --radius was already
  redefined in _theme-variables.scss (loaded after globals), so nothing breaks;
  repointed the 3 var(--color-primary) refs in _wordpress-pipeline.scss to
  var(--accent-primary). Font stack now resolves to IBM Plex (SCSS) — the
  Inter/JetBrains globals.css vars were unused.
- lib/utils.js: cn() now uses clsx only (no tailwind-merge).

Primitives (components/ui/*) converted to SCSS-only classes (.ui-*):
- dropdown-menu.jsx, command.jsx → new .ui-dropdown-* / .ui-command-* classes.
- skeleton.jsx → .ui-skeleton; popover.jsx → .ui-popover-panel.
- dialog/alert-dialog/select/sheet → dropped the tailwindcss-animate veneer;
  enter/exit animation now handled by SCSS [data-state] keyframes in _ui.scss.
- alert-dialog AlertDialogAction gained a `variant` prop so non-danger confirms
  keep their primary (not destructive) button.
- Modal.jsx → .sk-modal*; ConfirmDialog.jsx → .sk-confirm* (icon containers,
  colors via theme tokens, layout) — the two heaviest raw-Tailwind components.

SCSS:
- _utilities.scss: extended the existing shim with a "Tailwind-removal
  compatibility" layer covering every remaining utility class still referenced
  in pages/components (positioning, sizing, spacing, semantic colors mapped to
  theme tokens, sr-only, the handful of sm:/lg:/hover: variants actually used).
- _ui.scss: .ui-dropdown-*, .ui-command-*, .ui-skeleton, .ui-popover-panel,
  .sk-modal*, .sk-confirm*, and [data-state] enter/exit animations.

Verified:
- npm run build passes; CSS shrank ~16kB (Tailwind utility layer gone).
- Completeness audit (scratchpad script): 0 un-styled Tailwind tokens remain
  (only SCSS-nested BEM false positives).
- Visual smoke test (screenshots skill, mock data): dashboard / docker / servers
  render correctly with full theming.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 02:08:03 -04:00

98 lines
4.0 KiB
JavaScript

/* global process */
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
import { fileURLToPath } from 'url'
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
const frontendPort = Number(env.SERVERKIT_FRONTEND_PORT) || 41921
const apiTarget = (env.VITE_API_URL || 'http://localhost:47927/api/v1').replace(/\/api\/v1\/?$/, '')
const rawAllowedHosts = (env.VITE_ALLOWED_HOSTS || '').trim()
let allowedHosts
if (rawAllowedHosts === 'all') {
allowedHosts = true
} else if (rawAllowedHosts) {
allowedHosts = rawAllowedHosts.split(',').map(s => s.trim()).filter(Boolean)
}
return {
plugins: [react()],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
// Stable import path for plugin code:
// import { api, useAuth } from 'serverkit-sdk';
// Internal restructures of src/plugins/sdk are invisible
// to plugins as long as the named exports stay stable.
'serverkit-sdk': fileURLToPath(new URL('./src/plugins/sdk/index.js', import.meta.url)),
},
// Force every `react` / `react-dom` / `react-router-dom`
// import (host code AND plugin code loaded via
// import.meta.glob) to resolve to one copy. Without this
// Vite can hand plugins a different React instance if dep
// optimization runs mid-session, producing the
// "Invalid hook call / ReactCurrentDispatcher is null"
// crash inside the contributions hook.
//
// Do NOT add resolve.alias entries for these — aliasing to
// the package directory bypasses Vite's optimizeDeps and
// serves raw ESM, which (combined with pre-bundled
// react-dom) recreates the same two-copies problem from the
// other direction.
dedupe: ['react', 'react-dom', 'react-router-dom'],
},
optimizeDeps: {
// Pre-bundle the renderer at server start instead of
// discovering it lazily. Lazy discovery is what triggers the
// mid-session re-bundle that strands the open browser tab
// on a stale React URL.
include: ['react', 'react-dom', 'react-router-dom'],
},
server: {
port: frontendPort,
...(allowedHosts !== undefined ? { allowedHosts } : {}),
proxy: {
'/api': {
target: apiTarget,
changeOrigin: true,
},
'/socket.io': {
target: apiTarget,
changeOrigin: true,
ws: true,
},
},
// Enable polling for WSL (Windows filesystem doesn't support inotify)
watch: {
usePolling: true,
interval: 1000,
},
},
css: {
preprocessorOptions: {
scss: {
// Silence Dart Sass deprecation warnings for @import and slash-div
// These are expected during migration from LESS and will be addressed
// when moving to @use/@forward module system
silenceDeprecations: ['import', 'slash-div', 'legacy-js-api', 'global-builtin', 'color-functions', 'strict-unary'],
},
},
},
build: {
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
'vendor-react': ['react', 'react-dom', 'react-router-dom'],
'vendor-charts': ['recharts'],
'vendor-flow': ['@xyflow/react'],
'vendor-xterm': ['@xterm/xterm', '@xterm/addon-fit', '@xterm/addon-web-links'],
'vendor-icons': ['lucide-react'],
},
},
},
},
}
})