-
-
Notifications
You must be signed in to change notification settings - Fork 58
/
vite.config.ts
119 lines (113 loc) · 3.12 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import Inspect from 'vite-plugin-inspect'
import Markdown from 'vite-plugin-vue-markdown'
// @ts-ignore: the plugin should not be checked in the playground
import VueRouter from '../src/vite'
import {
getFileBasedRouteName,
getPascalCaseRouteName,
VueRouterAutoImports,
} from '../src'
import Vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig({
clearScreen: false,
build: {
sourcemap: true,
},
// optimizeDeps: {
// exclude: ['ufo', 'mlly', 'magic-string', 'fsevents'],
// },
plugins: [
VueRouter({
dataFetching: true,
extensions: ['.page.vue', '.vue', '.md'],
extendRoute(route) {
// console.log('extending route', route.meta)
// example of deleting routes
// if (route.name.startsWith('/users')) {
// route.delete()
// }
if (route.name === '/[name]') {
route.addAlias('/hello-vite-:name')
}
// if (route.name === '/deep/nesting') {
// const children = [...route]
// children.forEach((child) => {
// // TODO: remove one node while copying the children to its parent
// })
// }
// example moving a route (without its children to the root)
if (route.fullPath.startsWith('/deep/nesting/works/too')) {
route.parent!.insert(
'/at-root-but-from-nested',
route.components.get('default')!
)
// TODO: make it easier to access the root
let root = route
while (root.parent) {
root = root.parent
}
route.delete()
const newRoute = root.insert(
'custom.page.page.vue',
route.components.get('default')!
)
// newRoute.components.set('default', route.components.get('default')!)
newRoute.meta = {
'custom-meta': 'works',
}
}
},
beforeWriteFiles(root) {
root.insert(
'/from-root',
'/Users/posva/unplugin-vue-router/playground/src/pages/index.vue'
)
},
routesFolder: [
// can add multiple routes folders
{
src: 'src/pages',
// can even add params
// path: ':lang/',
},
{
src: 'src/docs',
path: 'docs/:lang/',
filePatterns: ['*/**/*'],
extensions: ['.md'],
},
// {
// src: 'src/features/',
// path: 'features-prefix/',
// },
],
logs: true,
// getRouteName: getPascalCaseRouteName,
exclude: [
'ignored',
'**/__*',
'**/__**/*',
'!*.component.vue',
// resolve(__dirname, './src/pages/ignored'),
//
// './src/pages/**/*.spec.ts',
],
}),
Vue({
include: [/\.vue$/, /\.md$/]
}),
Markdown(),
AutoImport({
imports: [VueRouterAutoImports],
}),
Inspect(),
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
})