Ctrl K
ComunidadGuías…

vite.config.ts

Rama main · réplica de lectura del repositorio original.

Archivo original ↗Preguntar a KiBot
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import basicSsl from '@vitejs/plugin-basic-ssl';
import path from 'path';
import { readFileSync } from 'fs';

// HTTPS dev server (default). Browsers only expose powerful APIs (mic, camera, clipboard) in a
// secure context (HTTPS, or localhost), so a phone on the LAN needs HTTPS. basic-ssl mints a
// self-signed cert — accept the one-time warning on the device. Opt out with `DEV_HTTPS=0`.
const httpsDev = process.env.DEV_HTTPS !== '0';

// Stamp the version this bundle is built from. The server compares it at runtime (/api/version):
// a deploy that updates the server without rebuilding dist/client is otherwise SILENT — an older
// client just discards a response whose shape changed, and the UI renders empty with no error.
const clientVersion = JSON.parse(readFileSync(path.resolve(__dirname, 'package.json'), 'utf8')).version;

export default defineConfig({
  define: { __SHRAGA_CLIENT_VERSION__: JSON.stringify(clientVersion) },
  plugins: [react(), ...(httpsDev ? [basicSsl()] : [])],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src/client'),
    },
  },
  // ai.libx.js (the model catalog) ships CommonJS. When it is symlinked to a sibling repo it sits OUTSIDE
  // node_modules, where vite's CommonJS handling does not apply by default — include it by name.
  optimizeDeps: { include: ['ai.libx.js/models'] },
  build: {
    outDir: 'dist/client',
    emptyOutDir: true,
    commonjsOptions: { include: [/ai\.libx\.js/, /node_modules/] },
  },
  server: {
    host: true,
    allowedHosts: true,
    // Add-on packages may be symlinked to sibling repos OUTSIDE this project root; vite's default
    // fs.allow (project root only) would 403 their source in dev. Allow the parent dir so
    // symlinked dev packages serve. Dev-only; prod bundles them.
    fs: { allow: [path.resolve(__dirname, '..')] },
    // Agent runtime state (data/ holds git clones + worktrees the agent churns constantly) is not
    // client source — watching it pegs CPU on reloads and OOMs small boxes.
    watch: { ignored: ['**/data/**', '**/.wt/**', '**/.tmp/**', '**/dist/**'] },
    proxy: (() => {
      // Backend port — overridable so a second dev stack can run on its own ports (DEV_SERVER_PORT).
      const p = process.env.DEV_SERVER_PORT || '3033';
      return {
        '/api': `http://localhost:${p}`,
        '/uploads': `http://localhost:${p}`,
        '/ws': { target: `ws://localhost:${p}`, ws: true },
        '/pty': { target: `ws://localhost:${p}`, ws: true },
      };
    })(),
  },
});