Skip to content

Latest commit

 

History

History
119 lines (95 loc) · 3.46 KB

File metadata and controls

119 lines (95 loc) · 3.46 KB

Migration to Vite + Svelte + TypeScript

Overview

This project has been fully modernized from vanilla JavaScript to a type-safe Svelte application with Vite bundling.

What Changed

Architecture

  • Before: Manual script tags, brittle file copying, no type checking
  • After: Vite bundler, Svelte components, full TypeScript support

Key Improvements

1. Type Safety

  • ✅ Full TypeScript coverage
  • ✅ Web Speech API types defined
  • ✅ Catches bugs at compile time (e.g., missing event listeners)
  • ✅ IDE autocomplete and inline documentation

2. Build System

  • ✅ Vite bundler (465ms builds vs several seconds)
  • ✅ Automatic dependency resolution (no more missing scripts/)
  • ✅ Tree-shaking and code splitting
  • ✅ Optimized bundle: 37KB JS (14.92KB gzipped)

3. Developer Experience

  • ✅ Hot Module Replacement (instant updates)
  • ✅ Dev server with proper base path handling
  • ✅ Type checking in CI/CD pipeline
  • ✅ Better error messages

4. Component Architecture

  • ✅ Reactive Svelte stores for state management
  • ✅ Reusable DependencyChecker component
  • ✅ Separation of concerns (types, stores, components)

File Structure

src/
├── App.svelte              # Main application component
├── main.ts                 # Entry point
├── app.css                 # Global styles
├── lib/
│   ├── components/
│   │   └── DependencyChecker.svelte   # Dependency validation UI
│   ├── stores/
│   │   └── dependencies.ts             # State management
│   └── types/
│       └── speech.ts                   # TypeScript type definitions

Scripts

{
  "dev": "vite",                    // Start dev server with HMR
  "build": "vite build",            // Production build
  "preview": "vite preview",        // Preview production build
  "check": "svelte-check",          // Type checking
  "test": "vitest",                 // Unit tests
  "test:e2e": "playwright test"     // E2E tests
}

CI/CD Updates

The GitHub Actions workflow now:

  1. Runs TypeScript type checking (npm run check)
  2. Builds with Vite (npm run build)
  3. Runs E2E tests
  4. Deploys to GitHub Pages with CNAME

Migration Benefits

Feature Before After
Type checking ❌ None ✅ Full TypeScript
Build time ~3-5s 465ms
Bundle size Unknown, multiple files 14.92KB gzipped
Dev server Manual ✅ HMR at localhost:5173
Missing deps Runtime errors ✅ Compile-time errors
Event listeners Manual attachment ✅ Svelte reactivity
State management Global window vars ✅ Svelte stores

Running the New Stack

Development

npm run dev
# Opens at http://localhost:5173/Talk-to-Unity/

Production Build

npm run build
npm run preview

Type Checking

npm run check

Legacy Code

The old vanilla JS implementation is preserved:

  • index.html.legacy - Original HTML
  • scripts/build.mjs - Legacy build script (available as npm run build:legacy)
  • landing.js - Old landing page logic (now in Svelte components)

Next Steps

Future enhancements:

  • Migrate voice interaction UI to Svelte components
  • Add Vitest unit tests for stores and components
  • Implement audio visualization with Svelte reactivity
  • Add speech recognition service with proper TypeScript types
  • PWA support for offline functionality