2026-06-24 17:00:29 +02:00
|
|
|
import { defineConfig, loadEnv, type Plugin } from 'vite'
|
2026-05-12 19:09:50 +02:00
|
|
|
import react from '@vitejs/plugin-react'
|
|
|
|
|
|
2026-06-24 17:00:29 +02:00
|
|
|
const UMAMI_SRC = 'https://stats.gethumanai.pl/script.js'
|
|
|
|
|
// Fallback website id, used when PUBLIC_UMAMI_WEBSITE_ID is not provided.
|
|
|
|
|
const UMAMI_FALLBACK_ID = 'f5a3fd87-5ae1-408d-85a6-7af588484d37'
|
|
|
|
|
|
|
|
|
|
// Injects the Umami analytics tag into <head>. `apply: 'build'` means it runs
|
|
|
|
|
// only for production builds (`vite build`) — never on the dev server.
|
|
|
|
|
function umami(websiteId: string): Plugin {
|
|
|
|
|
return {
|
|
|
|
|
name: 'inject-umami',
|
|
|
|
|
apply: 'build',
|
|
|
|
|
transformIndexHtml(html) {
|
|
|
|
|
const tag = `<script defer src="${UMAMI_SRC}" data-website-id="${websiteId}"></script>`
|
|
|
|
|
return html.replace('</head>', ` ${tag}\n </head>`)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-12 19:09:50 +02:00
|
|
|
// https://vitejs.dev/config/
|
2026-06-24 17:00:29 +02:00
|
|
|
export default defineConfig(({ mode }) => {
|
|
|
|
|
const env = loadEnv(mode, process.cwd(), '')
|
|
|
|
|
const websiteId = env.PUBLIC_UMAMI_WEBSITE_ID || UMAMI_FALLBACK_ID
|
|
|
|
|
return {
|
|
|
|
|
plugins: [react(), umami(websiteId)],
|
|
|
|
|
}
|
2026-05-12 19:09:50 +02:00
|
|
|
})
|