-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
77 lines (67 loc) · 2.17 KB
/
vite.config.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* eslint-disable import/no-extraneous-dependencies */
import { fileURLToPath, URL } from 'url';
import { createWriteStream } from 'fs';
import 'vite-ssg';
import { defineConfig } from 'vite';
import { SitemapStream } from 'sitemap';
import vue from '@vitejs/plugin-vue';
import svgIcon from './plugin/svgIcon';
import { getDeviconData, getSvgURL } from './plugin/data';
// https://vitejs.dev/config/
export default defineConfig({
base: process.env.BASE_URL,
plugins: [vue(), svgIcon()],
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
build: {
terserOptions: {
compress: {
// Prevent Infinity from being compressed to 1/0, may cause performance issues on Chrome
keep_infinity: true,
drop_console: false,
},
format: { comments: false },
},
minify: 'terser',
// Speed up packing
brotliSize: false,
chunkSizeWarningLimit: 2000,
},
ssgOptions: {
rootContainerId: 'app-mount',
formatting: 'minify',
dirStyle: 'nested',
script: 'async',
async onFinished() {
if (process.env.HOSTNAME) {
const smStream = new SitemapStream({
hostname: process.env.HOSTNAME,
lastmodDateOnly: false,
xmlns: { image: true, xhtml: true, news: false, video: false },
});
const images = [];
await getDeviconData().then((data) => {
Object.values(data)
.slice(0, 1000) // https://developers.google.com/search/docs/advanced/sitemaps/image-sitemaps
.forEach(({ versions: { svg }, name, tags }) => {
const svgVersion = svg?.[0];
if (svgVersion)
images.push({
url: getSvgURL(name, svgVersion),
title: `devicon-${name}`,
caption: tags.join(','),
license: 'https://github.com/devicons/devicon',
});
});
});
smStream.pipe(createWriteStream('./dist/sitemap.xml'));
smStream.write({
url: process.env.HOSTNAME,
changefreq: 'daily',
priority: 1,
img: images,
});
smStream.end();
}
},
},
});