-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathtransformIndexHtmlPlugin.ts
53 lines (49 loc) · 1.33 KB
/
transformIndexHtmlPlugin.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
46
47
48
49
50
51
52
53
import { PluginOption, ResolvedConfig } from 'vite'
export function transformIndexHtmlPlugin() {
let config: ResolvedConfig
return {
name: 'transformIndexHtmlPlugin',
enforce: 'post',
configResolved(resolvedConfig) {
// 存储最终解析的配置
config = resolvedConfig
},
transformIndexHtml(html: any) {
html = html.replace(/<title>.*?<\/title>/, '')
return {
html,
tags: [
{
tag: 'title',
children: 'Sard uniapp | Vue Component',
},
{
tag: 'meta',
attrs: {
name: 'description',
content: 'Sard uniapp | uniapp UI 组件库',
},
},
{
tag: 'link',
attrs: {
rel: 'icon',
type: 'image/svg+xml',
href: config.base + 'static/logo.svg',
},
},
{
tag: 'script',
children: `var _hmt = _hmt || []
;(function () {
var hm = document.createElement('script')
hm.src = 'https://hm.baidu.com/hm.js?f83f5174c995e2f5c9520acb67f574b9'
var s = document.getElementsByTagName('script')[0]
s.parentNode.insertBefore(hm, s)
})()`,
},
],
}
},
} as PluginOption
}