import { defineConfig } from 'vite' import { configDefaults } from 'vitest/config' import solidPlugin from 'vite-plugin-solid' import path from 'path' import fs from 'fs' import tailwindcss from '@tailwindcss/vite' function readJson(filePath) { try { return JSON.parse(fs.readFileSync(filePath, 'utf8')); } catch { return null; } } const keetPkg = readJson(path.resolve(__dirname, 'package.json')); const npmParakeetPkg = readJson(path.resolve(__dirname, 'node_modules/parakeet.js/package.json')); const npmVersion = npmParakeetPkg?.version; const parakeetVersion = npmVersion || 'unknown'; const parakeetSource = 'npm'; const onnxVersion = keetPkg?.dependencies?.['onnxruntime-web'] || npmParakeetPkg?.dependencies?.['onnxruntime-web'] || 'unknown'; console.log('Using NPM parakeet.js (v' + (npmVersion || '?') + ')'); // Optional HTTPS setup let httpsConfig = false; try { const keyPath = path.resolve('./localhost-key.pem'); const certPath = path.resolve('./localhost.pem'); if (fs.existsSync(keyPath) && fs.existsSync(certPath)) { httpsConfig = { key: fs.readFileSync(keyPath), cert: fs.readFileSync(certPath), }; console.log('✅ HTTPS enabled with local certificates'); } } catch (err) { httpsConfig = false; } // GitHub Pages project site is served at /keet/; set BASE_PATH in CI const base = process.env.BASE_PATH || '/'; export default defineConfig({ base, plugins: [ tailwindcss(), solidPlugin() ], server: { port: 3100, host: '0.0.0.0', headers: { 'Cross-Origin-Embedder-Policy': 'require-corp', 'Cross-Origin-Opener-Policy': 'same-origin', }, ...(httpsConfig && { https: httpsConfig }), }, build: { target: 'esnext', rollupOptions: { output: { assetFileNames: (assetInfo) => { if (assetInfo.name === 'audio-processor.js') { return 'assets/[name]-[hash][extname]'; } return 'assets/[name]-[hash][extname]'; }, }, }, }, optimizeDeps: { // Keep these ESM libs out of Vite's dev pre-bundler to avoid // intermittent missing-chunk warnings in node_modules/.vite/deps. exclude: [ 'audio-processor.js', 'parakeet.js', 'wink-nlp', 'wink-eng-lite-web-model', ], }, worker: { format: 'es', }, define: { __PARAKEET_VERSION__: JSON.stringify(parakeetVersion), __PARAKEET_SOURCE__: JSON.stringify(parakeetSource), __ONNXRUNTIME_VERSION__: JSON.stringify(onnxVersion), }, resolve: { alias: { '@': path.resolve(__dirname, './src'), }, }, test: { globals: true, environment: 'happy-dom', pool: 'forks', include: ['src/**/*.{test,spec}.{ts,tsx}'], exclude: [...configDefaults.exclude], deps: { optimizer: { web: { include: ['@vitest/web-worker'], }, }, }, }, })