This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vite.config.ts
90 lines (81 loc) · 2.43 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
78
79
80
81
82
83
84
85
86
87
88
89
90
import fs from "fs-extra";
import { resolve } from "path";
import { defineConfig } from "vite";
import prism from "markdown-it-prism";
import anchor from "markdown-it-anchor";
import markdownItAttrs from "markdown-it-attrs";
import matter from "gray-matter";
import Vue from "@vitejs/plugin-vue";
import VueJsx from "@vitejs/plugin-vue-jsx";
import Markdown from "vite-plugin-md";
import Pages from "vite-plugin-pages";
import UnoCSS from "unocss/vite";
import ViteCompression from "vite-plugin-compression";
import generateSitemap from "vite-plugin-pages-sitemap";
import "prismjs/components/prism-regex";
import "prismjs/components/prism-javascript";
import "prismjs/components/prism-typescript";
import "prismjs/components/prism-xml-doc";
import "prismjs/components/prism-yaml";
import "prismjs/components/prism-json";
import "prismjs/components/prism-markdown";
import "prismjs/components/prism-java";
import "prismjs/components/prism-javadoclike"; // for some reason prism needs this one
import "prismjs/components/prism-javadoc";
import "prismjs/components/prism-jsdoc";
// https://vitejs.dev/config/
export default defineConfig({
optimizeDeps: {
include: [],
},
resolve: {
alias: {
"@": resolve(__dirname, "src"),
},
},
plugins: [
ViteCompression(),
Vue({
include: [/\.vue$/, /\.md$/],
}),
VueJsx(),
UnoCSS(),
Pages({
extensions: ["vue", "md"],
extendRoute(route) {
const path = resolve(__dirname, route.component.slice(1));
if (path.endsWith(".md")) {
const md = fs.readFileSync(path, "utf-8");
const { data } = matter(md);
route.meta = Object.assign(route.meta || {}, { frontmatter: data });
}
return route;
},
onRoutesGenerated: routes =>
generateSitemap({
routes,
hostname: "https://vite.daolanfler.xyz/",
readable: true,
dest: "dist",
}),
}),
Markdown({
wrapperComponent: "post-wrapper",
markdownItSetup(md) {
md.use(markdownItAttrs);
md.use(anchor, {
permalink: anchor.permalink.headerLink(),
});
md.use(prism);
},
}),
],
ssgOptions: {
format: "esm",
includedRoutes(paths, routes) {
// 排除 challenges , cdn 引入无法 ssg, 但是刷新页面会有屏闪
// TODO 从 vite-ssg 升级到 nuxt
return paths.filter(p => !p.includes("challenge"));
},
},
});