velxio/frontend/vite.config.ts

89 lines
3.7 KiB
TypeScript
Raw Normal View History

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
// https://vite.dev/config/
fix(install): unblock self-hosting + drop forced wokwi clones Resolves several install pain points reported by users (#108, #120) and removes the obligatory upstream-clone step that confused contributors and slowed down every Docker build. Install fixes: - nginx: server_name → catch-all default_server, drop Debian's stock site so reverse-proxied users no longer get the "Welcome to nginx" page. - entrypoint: auto-generate SECRET_KEY at first boot, persisted under data/.secret_key. backend/.env is now optional in docker-compose.yml. - backend: add greenlet>=3.0.0 (SQLAlchemy async dep that was missing on some Python builds — caused uvicorn startup failures on WSL). Wokwi libs come from npm: - @wokwi/elements 1.9.2, avr8js 0.21.0, rp2040js 1.3.2 are pinned in frontend/package.json. Vite aliases removed. - Dockerfile.standalone no longer clones avr8js / rp2040js / wokwi-elements / wokwi-boards. Frontend stage is just COPY + npm install + build:docker. - Board SVGs vendored under frontend/public/boards/ (10 deduped against existing files, 2 truly new). third-party/wokwi-* clones become reference- only credits — generate-component-metadata.ts skips gracefully when absent. Production config split out: - docker-compose.prod.yml, deploy/nginx.prod.conf, nginx-host-velxio*.conf, update-third-party.bat removed. Production deployment lives in its own repo: https://github.com/velxio/velxio-prod (host nginx + HTTPS + backups + pinned upstream commit). Verified locally: 1161 frontend tests pass, build:docker completes clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-04 10:04:11 +07:00
// avr8js / rp2040js / @wokwi/elements are resolved from npm via package.json.
// (The third-party/ clones are reference-only — keep them updated for credits.)
//
// The `@pro` alias resolves to a no-op stub by default. Private overlays
// (e.g. velxio-prod) set VITE_PRO_BUILD=true and PRO_OVERLAY_PATH at build
// time to point at their actual pro source tree. See README's "Pro overlay"
// section.
const proOverlayPath =
process.env.VITE_PRO_BUILD && process.env.PRO_OVERLAY_PATH
? path.resolve(process.env.PRO_OVERLAY_PATH)
: path.resolve(__dirname, 'src/__pro_stub__')
export default defineConfig(({ command }) => ({
plugins: [react()],
resolve: {
alias: {
'@pro': proOverlayPath,
refactor(oss-split): remove auth/admin/profile frontend from OSS Phase 3 of the OSS / pro split — frontend side. Phase 2 already moved the auth/DB stack out of the OSS backend; this commit does the same for the React app. After this, the OSS image is editor + simulator + landing + docs only. What moved to the private overlay (pro/frontend/src/pro/): pages/{Login,Register,ForgotPassword,ResetPassword}Page.tsx pages/{Admin,UserProfile,Project,ProjectById}Page.tsx components/admin/{AdminBoardsTab,AdminDashboardTab,UserActivityModal}.tsx components/layout/{SaveProjectModal,LoginPromptModal}.tsx services/{authService,adminService}.ts store/useAuthStore.ts hooks/autoSaveImpl.ts New seams added so OSS components stay decoupled: * lib/proRoutes.ts — registerProRoutes()/useProRoutes() via useSyncExternalStore. mountPro() injects the moved pages at runtime; App.tsx subscribes to the registry, so registration after the initial render re-renders without a Not-Found flash. * lib/proSession.ts — registerSessionCheck()/triggerSessionCheck(). App.tsx fires this on mount instead of useAuthStore.checkSession(); pure OSS no-ops. * lib/proSaveAction.ts — installSaveActionImpl()/triggerSaveAction(). EditorPage's Save button dispatches through this; the overlay decides whether to show SaveProjectModal or LoginPromptModal based on auth state. In OSS without an overlay it's a no-op today; in Phase 4 of the split it becomes the .vlx Export entry point. OSS-side rewrites: * App.tsx drops the 8 page imports + 8 route entries; uses triggerSessionCheck() instead of useAuthStore directly. * AppHeader.tsx drops the user/login/register block entirely. The header-auth slot (introduced in Phase 1) now stays empty in OSS and gets filled by the overlay's portal mount. * EditorPage.tsx drops useAuthStore + SaveProjectModal + LoginPromptModal imports. The Save handler is now triggerSaveAction(). * LandingPage.tsx drops the dead UserMenu component (defined but never rendered) + its useAuthStore imports. * main.tsx drops the side-effect import of hooks/autoSaveImpl — the impl lives in pro now and self-registers via mountPro(). Build config: * vite.config.ts adds @velxio alias → src/. Lets the overlay import upstream modules (lib/proRoutes etc.) by stable name regardless of whether it's symlinked (local dev) or COPYed (Docker). * preserveSymlinks now gated on VITE_PRO_BUILD only (not on serve mode). Needed so Rollup keeps the overlay logically inside src/pro/ during local junction-based builds. Build verification: * OSS-only: 20-ish routes, no /login, /admin, /:username — 285 SEO pages prerendered. Bundle drops ~80-120 KB. * OSS + overlay: full 38 routes (30 upstream + 8 from registerProRoutes), HeaderAuth dropdown injected via slot, save action wired to the overlay's modal flow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 01:31:12 +07:00
// Stable alias for OSS modules that the pro overlay needs to import
// (e.g. lib/proRoutes for route registration). Using an alias instead
// of a relative path makes the import location-independent: it works
// whether the overlay is symlinked into src/pro/ (local dev — Rollup
// resolves the import from the real overlay path) or physically
// COPYed into src/pro/ (Docker build). Either way `@velxio/<x>`
// points at the OSS src tree.
'@velxio': path.resolve(__dirname, 'src'),
},
refactor(oss-split): remove auth/admin/profile frontend from OSS Phase 3 of the OSS / pro split — frontend side. Phase 2 already moved the auth/DB stack out of the OSS backend; this commit does the same for the React app. After this, the OSS image is editor + simulator + landing + docs only. What moved to the private overlay (pro/frontend/src/pro/): pages/{Login,Register,ForgotPassword,ResetPassword}Page.tsx pages/{Admin,UserProfile,Project,ProjectById}Page.tsx components/admin/{AdminBoardsTab,AdminDashboardTab,UserActivityModal}.tsx components/layout/{SaveProjectModal,LoginPromptModal}.tsx services/{authService,adminService}.ts store/useAuthStore.ts hooks/autoSaveImpl.ts New seams added so OSS components stay decoupled: * lib/proRoutes.ts — registerProRoutes()/useProRoutes() via useSyncExternalStore. mountPro() injects the moved pages at runtime; App.tsx subscribes to the registry, so registration after the initial render re-renders without a Not-Found flash. * lib/proSession.ts — registerSessionCheck()/triggerSessionCheck(). App.tsx fires this on mount instead of useAuthStore.checkSession(); pure OSS no-ops. * lib/proSaveAction.ts — installSaveActionImpl()/triggerSaveAction(). EditorPage's Save button dispatches through this; the overlay decides whether to show SaveProjectModal or LoginPromptModal based on auth state. In OSS without an overlay it's a no-op today; in Phase 4 of the split it becomes the .vlx Export entry point. OSS-side rewrites: * App.tsx drops the 8 page imports + 8 route entries; uses triggerSessionCheck() instead of useAuthStore directly. * AppHeader.tsx drops the user/login/register block entirely. The header-auth slot (introduced in Phase 1) now stays empty in OSS and gets filled by the overlay's portal mount. * EditorPage.tsx drops useAuthStore + SaveProjectModal + LoginPromptModal imports. The Save handler is now triggerSaveAction(). * LandingPage.tsx drops the dead UserMenu component (defined but never rendered) + its useAuthStore imports. * main.tsx drops the side-effect import of hooks/autoSaveImpl — the impl lives in pro now and self-registers via mountPro(). Build config: * vite.config.ts adds @velxio alias → src/. Lets the overlay import upstream modules (lib/proRoutes etc.) by stable name regardless of whether it's symlinked (local dev) or COPYed (Docker). * preserveSymlinks now gated on VITE_PRO_BUILD only (not on serve mode). Needed so Rollup keeps the overlay logically inside src/pro/ during local junction-based builds. Build verification: * OSS-only: 20-ish routes, no /login, /admin, /:username — 285 SEO pages prerendered. Bundle drops ~80-120 KB. * OSS + overlay: full 38 routes (30 upstream + 8 from registerProRoutes), HeaderAuth dropdown injected via slot, save action wired to the overlay's modal flow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 01:31:12 +07:00
// When the pro overlay is wired in via a junction/symlink
// (Windows pattern: `frontend/src/pro` → `velxio-prod/pro/frontend/src/pro`),
refactor(oss-split): remove auth/admin/profile frontend from OSS Phase 3 of the OSS / pro split — frontend side. Phase 2 already moved the auth/DB stack out of the OSS backend; this commit does the same for the React app. After this, the OSS image is editor + simulator + landing + docs only. What moved to the private overlay (pro/frontend/src/pro/): pages/{Login,Register,ForgotPassword,ResetPassword}Page.tsx pages/{Admin,UserProfile,Project,ProjectById}Page.tsx components/admin/{AdminBoardsTab,AdminDashboardTab,UserActivityModal}.tsx components/layout/{SaveProjectModal,LoginPromptModal}.tsx services/{authService,adminService}.ts store/useAuthStore.ts hooks/autoSaveImpl.ts New seams added so OSS components stay decoupled: * lib/proRoutes.ts — registerProRoutes()/useProRoutes() via useSyncExternalStore. mountPro() injects the moved pages at runtime; App.tsx subscribes to the registry, so registration after the initial render re-renders without a Not-Found flash. * lib/proSession.ts — registerSessionCheck()/triggerSessionCheck(). App.tsx fires this on mount instead of useAuthStore.checkSession(); pure OSS no-ops. * lib/proSaveAction.ts — installSaveActionImpl()/triggerSaveAction(). EditorPage's Save button dispatches through this; the overlay decides whether to show SaveProjectModal or LoginPromptModal based on auth state. In OSS without an overlay it's a no-op today; in Phase 4 of the split it becomes the .vlx Export entry point. OSS-side rewrites: * App.tsx drops the 8 page imports + 8 route entries; uses triggerSessionCheck() instead of useAuthStore directly. * AppHeader.tsx drops the user/login/register block entirely. The header-auth slot (introduced in Phase 1) now stays empty in OSS and gets filled by the overlay's portal mount. * EditorPage.tsx drops useAuthStore + SaveProjectModal + LoginPromptModal imports. The Save handler is now triggerSaveAction(). * LandingPage.tsx drops the dead UserMenu component (defined but never rendered) + its useAuthStore imports. * main.tsx drops the side-effect import of hooks/autoSaveImpl — the impl lives in pro now and self-registers via mountPro(). Build config: * vite.config.ts adds @velxio alias → src/. Lets the overlay import upstream modules (lib/proRoutes etc.) by stable name regardless of whether it's symlinked (local dev) or COPYed (Docker). * preserveSymlinks now gated on VITE_PRO_BUILD only (not on serve mode). Needed so Rollup keeps the overlay logically inside src/pro/ during local junction-based builds. Build verification: * OSS-only: 20-ish routes, no /login, /admin, /:username — 285 SEO pages prerendered. Bundle drops ~80-120 KB. * OSS + overlay: full 38 routes (30 upstream + 8 from registerProRoutes), HeaderAuth dropdown injected via slot, save action wired to the overlay's modal flow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 01:31:12 +07:00
// Rollup's default behavior walks the symlink to the real path and
// resolves imports from THAT location — but the real overlay path
// has no node_modules nearby AND its `../../<x>` paths land outside
// the OSS src tree. Preserving symlinks keeps the overlay logically
// anchored inside src/pro/.
//
refactor(oss-split): remove auth/admin/profile frontend from OSS Phase 3 of the OSS / pro split — frontend side. Phase 2 already moved the auth/DB stack out of the OSS backend; this commit does the same for the React app. After this, the OSS image is editor + simulator + landing + docs only. What moved to the private overlay (pro/frontend/src/pro/): pages/{Login,Register,ForgotPassword,ResetPassword}Page.tsx pages/{Admin,UserProfile,Project,ProjectById}Page.tsx components/admin/{AdminBoardsTab,AdminDashboardTab,UserActivityModal}.tsx components/layout/{SaveProjectModal,LoginPromptModal}.tsx services/{authService,adminService}.ts store/useAuthStore.ts hooks/autoSaveImpl.ts New seams added so OSS components stay decoupled: * lib/proRoutes.ts — registerProRoutes()/useProRoutes() via useSyncExternalStore. mountPro() injects the moved pages at runtime; App.tsx subscribes to the registry, so registration after the initial render re-renders without a Not-Found flash. * lib/proSession.ts — registerSessionCheck()/triggerSessionCheck(). App.tsx fires this on mount instead of useAuthStore.checkSession(); pure OSS no-ops. * lib/proSaveAction.ts — installSaveActionImpl()/triggerSaveAction(). EditorPage's Save button dispatches through this; the overlay decides whether to show SaveProjectModal or LoginPromptModal based on auth state. In OSS without an overlay it's a no-op today; in Phase 4 of the split it becomes the .vlx Export entry point. OSS-side rewrites: * App.tsx drops the 8 page imports + 8 route entries; uses triggerSessionCheck() instead of useAuthStore directly. * AppHeader.tsx drops the user/login/register block entirely. The header-auth slot (introduced in Phase 1) now stays empty in OSS and gets filled by the overlay's portal mount. * EditorPage.tsx drops useAuthStore + SaveProjectModal + LoginPromptModal imports. The Save handler is now triggerSaveAction(). * LandingPage.tsx drops the dead UserMenu component (defined but never rendered) + its useAuthStore imports. * main.tsx drops the side-effect import of hooks/autoSaveImpl — the impl lives in pro now and self-registers via mountPro(). Build config: * vite.config.ts adds @velxio alias → src/. Lets the overlay import upstream modules (lib/proRoutes etc.) by stable name regardless of whether it's symlinked (local dev) or COPYed (Docker). * preserveSymlinks now gated on VITE_PRO_BUILD only (not on serve mode). Needed so Rollup keeps the overlay logically inside src/pro/ during local junction-based builds. Build verification: * OSS-only: 20-ish routes, no /login, /admin, /:username — 285 SEO pages prerendered. Bundle drops ~80-120 KB. * OSS + overlay: full 38 routes (30 upstream + 8 from registerProRoutes), HeaderAuth dropdown injected via slot, save action wired to the overlay's modal flow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-15 01:31:12 +07:00
// In Docker builds the overlay is COPYed in physically (no symlinks
// to follow), so this flag is effectively a no-op there. We keep it
// gated on VITE_PRO_BUILD so OSS-only builds without the overlay
// see the default behavior.
preserveSymlinks: !!process.env.VITE_PRO_BUILD,
},
server: {
proxy: {
'/api': {
target: 'http://127.0.0.1:8001',
changeOrigin: true,
},
},
},
assetsInclude: ['**/*.wasm'],
optimizeDeps: {
include: ['avr8js', 'rp2040js', '@wokwi/elements', 'littlefs'],
},
build: {
// Phase 1d #4 — split heavy long-lived chunks so cache-hits stay
// meaningful and the cold-load entry stays small. The previous
// bundle landed the whole app + Monaco + every MCU sim in one
// index chunk (>23 MB). Manual chunks below collapse it into
// cacheable groups that match the user's actual flow (editor
// load, run simulator, edit code in Monaco).
rollupOptions: {
output: {
manualChunks: {
// ngspice WASM client — only loaded when the user opens
// a circuit with electrical components.
'spice-wasm': [
'./src/simulation/spice/adapters/NgSpiceWorkerAdapter.ts',
'./src/simulation/spice/wasm/NgSpiceInteractive.ts',
],
// MCU emulators — bulky, infrequent updates.
'mcu-emulators': ['avr8js', 'rp2040js'],
// Wokwi visual elements — large but cacheable; only loaded
// once per session.
'wokwi-elements': ['@wokwi/elements'],
// React vendor — stable across deploys, near-permanent cache.
'react-vendor': ['react', 'react-dom', 'react-router-dom'],
},
},
},
chunkSizeWarningLimit: 8000,
},
test(sim): Phase 1d-tests J + C — vitest.config.ts + components-metadata integrity J: vitest.config.ts split out from inline `test:` block in vite.config.ts. CI workflows can now reference vitest.config.ts directly; test settings no longer pulled into vite build deps. Settings: testTimeout 30s, hookTimeout 30s, forks pool with singleFork:false (per-file worker isolation for the NgSpiceNodeAdapter singleton), coverage excludes `src/simulation/spice/wasm/**` (irrelevant lcov bytes). C: components-metadata-integrity.test.ts — 11 sub-tests, all live checks against the real `public/components-metadata.json` + every examples-*.ts source-of-truth + the live PartSimulationRegistry: • Shape per entry: id / tagName / name / category / pinCount • IDs unique • tagName matches wokwi/velxio prefix • Thumbnail is an SVG • properties[] + defaultValues{} shape • Every metadataId referenced from gallery exists in metadata (instr-* filtered — instruments aren't canvas-rendered) • PartSimulationRegistry registrations cross-checked vs metadata (informational — some runtime-only parts have no metadata entry by design: custom-chip, raspberry-pi-3, 74hc595 internals) • Orphan-entries report: surfaces metadata entries no example or part-sim uses (informational, doesn't fail) The orphan report flags 58 dead-ish metadata entries (preset variants like resistor-220, individual epaper sizes, etc.) for later cleanup conversation. Not an error. `PartSimulationRegistry.listRegisteredParts()` exposed for the test to enumerate without duplicating the list. 1472 tests pass (was 1461 — +11 new metadata sub-tests). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-16 03:58:12 +07:00
// Vitest config lives in `vitest.config.ts` (split out so CI can
// reference it directly and so vite build doesn't pay test deps).
}))