import path from 'node:path'; import strip from '@rollup/plugin-strip'; import react from '@vitejs/plugin-react'; import { defineConfig, type Plugin } from 'vite'; /** * Vite в проде вешает `crossorigin` на script/link; при открытии HTML через `file://` в Electron * на Windows это часто приводит к тихому отказу загрузки ES-модулей (чёрный экран). macOS может «проглатывать». */ function stripCrossoriginForElectronFile(): Plugin { return { name: 'strip-crossorigin-electron-file', enforce: 'post', apply: 'build', transformIndexHtml(html) { return html.replace(/\s+crossorigin(?:=["']?[^"'>\s]+["']?)?/gi, ''); }, }; } export default defineConfig(({ mode }) => { const isProd = mode === 'production'; return { /** Иначе в упакованном Electron `file://` запросы идут в `/assets/...` с корня диска — чёрный экран. */ base: isProd ? './' : '/', root: path.resolve(__dirname, 'app/renderer'), plugins: [ react({ babel: { plugins: [['babel-plugin-react-compiler', { target: '19' }]], }, } as Parameters[0]), ...(isProd ? [stripCrossoriginForElectronFile()] : []), ], build: { outDir: path.resolve(__dirname, 'dist/renderer'), emptyOutDir: true, sourcemap: !isProd, rollupOptions: { plugins: isProd ? [ strip({ sourceMap: false, debugger: true, functions: ['console.*', 'assert.*'], }), ] : [], input: { boot: path.resolve(__dirname, 'app/renderer/boot.html'), editor: path.resolve(__dirname, 'app/renderer/editor.html'), presentation: path.resolve(__dirname, 'app/renderer/presentation.html'), control: path.resolve(__dirname, 'app/renderer/control.html'), }, }, }, server: { port: 5173, strictPort: true, }, }; });