-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
52 lines (48 loc) · 1.2 KB
/
Copy pathvite.config.ts
File metadata and controls
52 lines (48 loc) · 1.2 KB
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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import {
indexRobots,
resolveSeoRoute,
socialImageUrl,
} from './src/app/shared/lib/seoRoutes.js'
const homeRoute = resolveSeoRoute('/')
function escapeHtml(value: string): string {
return value
.replace(/&/gu, '&')
.replace(/</gu, '<')
.replace(/>/gu, '>')
.replace(/"/gu, '"')
.replace(/'/gu, ''')
}
const seoTemplateValues = {
__ROUTEVEIL_SEO_CANONICAL__: homeRoute.canonicalUrl ?? '',
__ROUTEVEIL_SEO_DESCRIPTION__: homeRoute.description,
__ROUTEVEIL_SEO_IMAGE__: socialImageUrl,
__ROUTEVEIL_SEO_ROBOTS__: indexRobots,
__ROUTEVEIL_SEO_TITLE__: homeRoute.title,
}
export default defineConfig({
plugins: [
react(),
{
name: 'routeveil-seo-template',
transformIndexHtml(html) {
return Object.entries(seoTemplateValues).reduce(
(output, [token, value]) => output.replaceAll(token, escapeHtml(value)),
html,
)
},
},
],
build: {
outDir: 'dist/demo',
emptyOutDir: true,
chunkSizeWarningLimit: 600,
minify: 'terser',
terserOptions: {
format: {
comments: false,
},
},
},
})