diff --git a/index.html b/index.html index f67a837..bde143c 100644 --- a/index.html +++ b/index.html @@ -65,8 +65,8 @@
- - + + diff --git a/vite.config.ts b/vite.config.ts index 3c9dcf8..db45ab9 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,10 +5,20 @@ import tailwindcss from "@tailwindcss/vite" import { VitePWA } from 'vite-plugin-pwa' // https://vite.dev/config/ -export default defineConfig({ +export default defineConfig(({ mode }) => ({ plugins: [ react(), tailwindcss(), + // HTML 替换插件 - 仅在生产环境注入 Cloudflare Analytics + { + name: 'html-transform', + transformIndexHtml(html) { + const cloudflareScript = mode === 'production' + ? `` + : ''; + return html.replace('', cloudflareScript); + } + }, VitePWA({ registerType: 'autoUpdate', includeAssets: ['lite.svg', 'robots.txt', 'sitemap.xml'], @@ -130,4 +140,4 @@ export default defineConfig({ }, chunkSizeWarningLimit: 500, }, -}) +}))