-
-
Notifications
You must be signed in to change notification settings - Fork 83
/
vite.config.ts
168 lines (162 loc) · 5.04 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
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
156
157
158
159
160
161
162
163
164
165
166
167
168
import { fileURLToPath, URL } from 'url'
import { defineConfig } from 'vite'
import { join } from 'node:path'
import Inspect from 'vite-plugin-inspect'
import Markdown from 'unplugin-vue-markdown/vite'
// @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'
import VueDevtools from 'vite-plugin-vue-devtools'
export default defineConfig({
clearScreen: false,
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
'~': fileURLToPath(new URL('./src', import.meta.url)),
'unplugin-vue-router/runtime': fileURLToPath(
new URL('../src/runtime.ts', import.meta.url)
),
'unplugin-vue-router/types': fileURLToPath(
new URL('../src/types.ts', import.meta.url)
),
'unplugin-vue-router/data-loaders/basic': fileURLToPath(
new URL('../src/data-loaders/entries/basic.ts', import.meta.url)
),
'unplugin-vue-router/data-loaders/pinia-colada': fileURLToPath(
new URL('../src/data-loaders/entries/pinia-colada.ts', import.meta.url)
),
'unplugin-vue-router/data-loaders': fileURLToPath(
new URL('../src/data-loaders/entries/index.ts', import.meta.url)
),
},
},
build: {
sourcemap: true,
},
optimizeDeps: {
exclude: [
// easier to test with yalc
'@pinia/colada',
],
},
plugins: [
VueRouter({
extensions: ['.page.vue', '.vue'],
importMode: 'async',
experimental: {
autoExportsDataLoaders: ['src/loaders/**/*', '@/loaders/**/*'],
},
extendRoute(route) {
route.params.forEach((param, i) => {
// transform kebab-case to camelCase
param.paramName = param.paramName.replace(/-([a-z])/g, (g) =>
g[1].toUpperCase()
)
})
// 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',
route.components.get('default')!
)
// newRoute.components.set('default', route.components.get('default')!)
newRoute.meta = {
'custom-meta': 'works',
}
}
},
beforeWriteFiles(root) {
root.insert('/from-root', join(__dirname, './src/pages/index.vue'))
},
routesFolder: [
// can add multiple routes folders
{
src: 'src/pages',
},
{
src: 'src/docs',
path: 'docs/[lang]/',
// doesn't take into account files directly at src/docs, only subfolders
filePatterns: ['*/**'],
// ignores .vue files
extensions: ['.md'],
},
{
src: 'src/features',
filePatterns: '*/pages/**/*',
path: (file) => {
const prefix = 'src/features'
// +1 for the starting slash
file = file
.slice(file.lastIndexOf(prefix) + prefix.length + 1)
.replace('/pages', '')
// console.log('👉 FILE', file)
return file
},
},
],
logs: true,
// getRouteName: getPascalCaseRouteName,
exclude: [
'**/ignored/**',
// '**/ignored/**/*',
'**/__*',
'**/__**/*',
'**/*.component.vue',
// resolve(__dirname, './src/pages/ignored'),
//
// './src/pages/**/*.spec.ts',
],
}),
Vue({
include: [/\.vue$/, /\.md$/],
}),
Markdown({}),
AutoImport({
imports: [
VueRouterAutoImports,
{
// NOTE: we need to match the resolved paths to local files for development
// instead of just 'unplugin-vue-router/data-loaders/basic': ['defineBasicLoader'],
[fileURLToPath(
new URL('../src/data-loaders/entries/basic.ts', import.meta.url)
)]: ['defineBasicLoader'],
// [fileURLToPath(
// new URL('../src/data-loaders/entries/pinia-colada.ts', import.meta.url)
// )]: ['defineColadaLoader'],
},
],
}),
VueDevtools(),
Inspect(),
],
})