-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
101 lines (96 loc) · 2.79 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
91
92
93
94
95
96
97
98
99
100
101
import { defineConfig } from "vite"
import Vue from "@vitejs/plugin-vue"
import Pages from "vite-plugin-pages"
import Components from "unplugin-vue-components/vite"
import Markdown from "vite-plugin-md"
import matter from "gray-matter"
import fm from "front-matter"
import yaml, { dump } from "js-yaml"
import AutoImport from "unplugin-auto-import/vite"
import { resolve } from "path"
import { readFileSync } from "fs"
import commonjsExternals from 'vite-plugin-commonjs-externals';
const bundledWorker = require(resolve(__dirname, './plugins/vite-plugin-bundled-worker'));
// https://vitejs.dev/config/
export default defineConfig({
server: {
fs: {
allow: [".."],
},
},
resolve: {
alias: {
"~/": `${resolve(__dirname, "src")}/`,
},
},
define: {
"process.env": process.env,
},
plugins: [
bundledWorker(),
commonjsExternals({ externals: require('./external-packages').default }),
Vue({
include: [/\.vue$/, /\.ftml$/, /\.md$/],
}),
// https://github.com/antfu/vite-plugin-md
Markdown({
wrapperComponent: "post",
include: [/\.ftml$/, /\.md$/],
transforms: {
before: (content) => {
const res = fm(content)
const mdencodecontent = encodeURIComponent(res.body)
const mdfrontmatterstr = "---\n"+dump(res.attributes,{forceQuotes: true})+"---\n"
const mdcontent = mdfrontmatterstr+mdencodecontent
return mdcontent
}
}
}),
// https://github.com/hannoeru/vite-plugin-pages
Pages({
pagesDir: [
{
dir: "src/pages",
baseRoute: "",
},
{
dir: "public/wdfiles",
baseRoute: "wdfiles",
},
{
dir: "src/pages/user",
baseRoute: "user:info",
},
{
dir: "src/pages/tags",
baseRoute: "system:page-tags/tag",
}
],
extensions: ["vue", "ftml", "md"],
extendRoute(route) {
// Get inspired from anthony fu"s personal website
// https://github.com/antfu/antfu.me
const path = resolve(__dirname, route.component.slice(1))
const md = readFileSync(path, "utf-8")
const { data } = matter(md)
if (path.split(".").pop() == "ftml") {
route.meta = Object.assign(route.meta || {}, { frontmatter: data})
}
},
}),
// https://github.com/antfu/unplugin-vue-components
Components({
extensions: ["vue", "ftml", "md"],
include: [/\.vue$/, /\.vue\?vue/, /\.ftml$/, /\.md$/],
dts: true,
}),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
imports: ["vue", "@vueuse/core", "@vueuse/head", "vue-router"],
dts: true,
}),
],
optimizeDeps: {
include: ["vue", "vue-router", "@vueuse/core"],
},
})