import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import { sentryVitePlugin } from '@sentry/vite-plugin'; import { wasm } from '@rollup/plugin-wasm'; import inject from '@rollup/plugin-inject'; import { viteStaticCopy } from 'vite-plugin-static-copy'; import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin'; import { VitePWA } from 'vite-plugin-pwa'; import fs from 'fs'; import path from 'path'; import buildConfig from './build.config'; const copyFiles = { targets: [ { // Element Call's dist must land flat in public/element-call/ so the call // widget URL (/public/element-call/index.html) resolves. v4.x of // vite-plugin-static-copy preserves the full source path under dest, so // we strip the 4 leading segments of the source base // (node_modules/@element-hq/element-call-embedded/dist) — mirroring the // stripBase pattern used by the android/locales targets below. The old // `rename: 'element-call'` form silently produced // public/node_modules/.../dist/ under v4.x, 404ing the widget (calls // broke on cinny-desktop; web only worked because its deployed copy was // a stale artifact from before the vite-plugin-static-copy v4 bump). src: 'node_modules/@element-hq/element-call-embedded/dist', dest: 'public/element-call', rename: { stripBase: 4 }, }, { src: 'config.json', dest: '', }, { src: 'public/manifest.json', dest: '', rename: { stripBase: true }, }, { src: 'public/res/android', dest: 'public/', rename: { stripBase: 2 }, }, { src: 'public/locales', dest: 'public/', rename: { stripBase: 1 }, }, { src: 'public/fonts', dest: '', rename: { stripBase: 1 }, }, ], }; function copyPdfWorker() { return { name: 'copy-pdf-worker', closeBundle() { const src = path.resolve('node_modules/pdfjs-dist/build/pdf.worker.min.mjs'); const dest = path.resolve('dist/pdf.worker.min.js'); if (fs.existsSync(src)) fs.copyFileSync(src, dest); }, }; } // Lotus ML noise suppression: ship the RNNoise worklet/wasm + our getUserMedia // shim alongside the vendored Element Call bundle, and inject the shim