-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
64 lines (59 loc) · 1.92 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
import MarkdownItKatex from "@traptitech/markdown-it-katex";
import Vue from "@vitejs/plugin-vue";
import VueJSX from "@vitejs/plugin-vue-jsx";
import glob from "glob";
import MarkdownItAnchor from "markdown-it-anchor";
import MarkdownItTOC from "markdown-it-toc-done-right";
import { fileURLToPath, URL } from "url";
import { promisify } from "util";
import type { UserConfigExport } from "vite";
import ViteMD from "vite-plugin-md";
import { VitePWA } from "vite-plugin-pwa";
import type { ManifestEntry } from "workbox-build";
let publicDir = fileURLToPath(new URL("./public", import.meta.url));
if (publicDir.endsWith("/")) publicDir = publicDir.slice(0, -1);
let revision = Math.random().toString().slice(2);
async function getPublicEntries() {
let entries: ManifestEntry[] = [];
let files = await promisify(glob)(`${publicDir}/**/*`);
for (let file of files) {
let relativePath = file.slice(publicDir.length);
if (relativePath.includes("404.html")) continue;
entries.push({ url: relativePath, revision });
}
return entries;
}
export default new Promise<UserConfigExport>(async (resolve) =>
resolve({
publicDir,
plugins: [
Vue({ include: [/\.vue$/, /\.md$/] }),
VueJSX(),
ViteMD({
wrapperComponent: "Prose",
markdownItSetup(markdown) {
markdown
.use(MarkdownItKatex, { throwOnError: false })
.use(MarkdownItAnchor)
.use(MarkdownItTOC, { listType: "ul" });
},
}),
VitePWA({
workbox: {
navigateFallback: "/index.html",
cleanupOutdatedCaches: true,
sourcemap: false,
clientsClaim: true,
skipWaiting: true,
additionalManifestEntries: await getPublicEntries(),
maximumFileSizeToCacheInBytes: 1024 ** 5,
},
}),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
})
);