-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
vite.config.demo.ts
45 lines (40 loc) · 1.27 KB
/
vite.config.demo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { UserConfig } from 'vite'
const DEMO_BASE_PATH = '/surmon.admin/'
const GOOGLE_ANALYTICS_MEASUREMENT_ID = 'G-WNSSKPKKMG'
const GOOGLE_ADSENSE_CLIENT_ID = 'ca-pub-4710915636313788'
const DEMO_HACK_SCRIPT = `<script src="${DEMO_BASE_PATH}__demo__/index.js"></script>`
const GOOGLE_ANALYTICS_TAG_SCRIPT = `
<script async src="https://www.googletagmanager.com/gtag/js?id=${GOOGLE_ANALYTICS_MEASUREMENT_ID}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${GOOGLE_ANALYTICS_MEASUREMENT_ID}');
</script>
`
const GOOGLE_ADSENSE_SCRIPT = `
<script
async
crossorigin="anonymous"
src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=${GOOGLE_ADSENSE_CLIENT_ID}"
></script>
`
export const demoConfiger = (defaultConfig: UserConfig): UserConfig => {
return {
...defaultConfig,
// base path
base: DEMO_BASE_PATH,
plugins: [
...Array.from(defaultConfig.plugins!),
{
name: 'demo-html-transform',
transformIndexHtml(html) {
return html.replace(
`<!-- DEMO_SLOT -->`,
[DEMO_HACK_SCRIPT, GOOGLE_ANALYTICS_TAG_SCRIPT, GOOGLE_ADSENSE_SCRIPT].join('\n')
)
}
}
]
}
}