-
Notifications
You must be signed in to change notification settings - Fork 31
/
vite.config.js
155 lines (145 loc) · 3.56 KB
/
vite.config.js
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import * as path from 'node:path'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Markdown from 'unplugin-vue-markdown/vite'
import Pages from 'vite-plugin-pages'
import Restart from 'vite-plugin-restart'
import VueDevTools from 'vite-plugin-vue-devtools'
import Components from 'unplugin-vue-components/vite'
import Layouts from 'vite-plugin-vue-layouts'
import AutoImport from 'unplugin-auto-import/vite'
import Inspect from 'vite-plugin-inspect'
import Unocss from 'unocss/vite'
import Prism from 'markdown-it-prism'
import LinkAttributes from 'markdown-it-link-attributes'
import vueI18n from '@intlify/unplugin-vue-i18n/vite'
import pkg from './package.json'
const markdownWrapperClasses = 'prose prose-sm m-auto text-left'
process.env.VITE_APP_BUILD_EPOCH = new Date().getTime()
process.env.VITE_APP_VERSION = pkg.version
/**
* @type {import('vite').UserConfig}
*/
export default defineConfig({
server: {
hmr: {
port: false,
path: '/ws',
},
},
// https://github.com/antfu/vite-ssg
ssgOptions: {
script: 'async',
formatting: 'minify',
},
test: {
globals: true,
include: ['test/**/*.test.ts'],
environment: 'happy-dom',
},
optimizeDeps: {
include: [
'vue-router',
'@vueuse/core',
],
exclude: [
'vue',
'vue-demi',
],
},
plugins: [
Unocss({}),
Vue({
include: [/\.vue$/, /\.md$/],
template: {
compilerOptions: {
directiveTransforms: {
styleclass: () => ({
props: [],
needRuntime: true,
}),
ripple: () => ({
props: [],
needRuntime: true,
}),
},
},
},
}),
vueI18n({
include: path.resolve(__dirname, './src/locales/**'),
}),
Components({
dts: 'src/components.d.ts',
resolvers: [
],
}),
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
Layouts(),
// https://github.com/webfansplz/vite-plugin-vue-devtools
VueDevTools(),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
imports: [
'vue',
'vue-router',
'vue-i18n',
'@vueuse/head',
],
exclude: [
'**/dist/**',
],
dts: 'src/auto-import.d.ts',
}),
Pages({
// pagesDir: ['src/pages', 'src/pages2'],
pagesDir: [
{ dir: 'src/pages', baseRoute: '' },
],
extensions: ['vue', 'md'],
syncIndex: true,
replaceSquareBrackets: true,
extendRoute(route) {
if (route.name === 'about')
route.props = route => ({ query: route.query.q })
if (route.name === 'components') {
return {
...route,
beforeEnter: (route) => {
// console.log(route)
},
}
}
},
}),
Markdown({
wrapperClasses: markdownWrapperClasses,
headEnabled: true,
markdownItSetup(md) {
// https://prismjs.com/
md.use(Prism)
md.use(LinkAttributes, {
matcher: link => /^https?:\/\//.test(link),
attrs: {
target: '_blank',
rel: 'noopener',
},
})
},
}),
Restart({
restart: ['../../dist/*.js'],
}),
// https://github.com/antfu/vite-plugin-inspect
Inspect({
// change this to enable inspect for debugging
enabled: false,
}),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'~': path.resolve(__dirname, 'node_modules/'),
},
},
})