mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
Load analytics tags from config during Vite build
This commit is contained in:
+15
-1
@@ -1,9 +1,23 @@
|
|||||||
import { defineConfig } from 'vite'
|
import { defineConfig } from 'vite'
|
||||||
import react from '@vitejs/plugin-react'
|
import react from '@vitejs/plugin-react'
|
||||||
|
import fs from 'node:fs'
|
||||||
|
|
||||||
|
const ANALYTICS_PLACEHOLDER = '<!-- analytics:inject -->'
|
||||||
|
|
||||||
|
function analyticsTags() {
|
||||||
|
return {
|
||||||
|
name: 'analytics-tags',
|
||||||
|
transformIndexHtml(html) {
|
||||||
|
const tagsPath = new URL('./src/config/analytics.html', import.meta.url)
|
||||||
|
const tags = fs.existsSync(tagsPath) ? fs.readFileSync(tagsPath, 'utf8').trim() : ''
|
||||||
|
return html.replace(ANALYTICS_PLACEHOLDER, tags)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://vite.dev/config/
|
// https://vite.dev/config/
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react(), analyticsTags()],
|
||||||
build: {
|
build: {
|
||||||
outDir: '../server/public',
|
outDir: '../server/public',
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user