import { resolve } from 'path' import react from '@vitejs/plugin-react' import { defineConfig } from 'vite' import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js' // IIFE format: component registers itself in window.GlitchComponents at load time. // react/jsx-runtime is intentionally NOT external — it gets bundled and reads from window.React. // Host apps must expose window.React and window.ReactDOM before loading any component script. export default defineConfig(({ mode }) => ({ plugins: [react(), cssInjectedByJsPlugin()], build: { lib: { entry: resolve(__dirname, 'src/index.tsx'), name: 'GlitchComponent', fileName: () => 'bloodsugar.js', formats: ['iife'] }, rollupOptions: { external: ['react', 'react-dom'], output: { globals: { react: 'React', 'react-dom': 'ReactDOM', }, assetFileNames: 'assets/[name][extname]', exports: 'named' } }, sourcemap: true, minify: mode === 'production' }, server: { port: 3001, open: true } }))