refactor: update loadPlugin to use async/await and improve vueRouter configuration
This commit is contained in:
@@ -1,11 +1,10 @@
|
|||||||
import vue from '@vitejs/plugin-vue';
|
import vue from '@vitejs/plugin-vue';
|
||||||
import vueJsx from '@vitejs/plugin-vue-jsx';
|
import vueJsx from '@vitejs/plugin-vue-jsx';
|
||||||
import { getPascalCaseRouteName } from 'unplugin-vue-router';
|
|
||||||
import vueRouter from 'unplugin-vue-router/vite';
|
import vueRouter from 'unplugin-vue-router/vite';
|
||||||
import type { ConfigEnv, PluginOption } from 'vite';
|
import type { ConfigEnv, PluginOption } from 'vite';
|
||||||
import VueMacros from 'vue-macros/vite';
|
import VueMacros from 'vue-macros/vite';
|
||||||
|
|
||||||
export function loadPlugin(_configEnv: ConfigEnv): PluginOption {
|
export async function loadPlugin(_configEnv: ConfigEnv): Promise<PluginOption> {
|
||||||
return [
|
return [
|
||||||
VueMacros({
|
VueMacros({
|
||||||
plugins: {
|
plugins: {
|
||||||
@@ -16,11 +15,16 @@ export function loadPlugin(_configEnv: ConfigEnv): PluginOption {
|
|||||||
// https://github.com/posva/unplugin-vue-router
|
// https://github.com/posva/unplugin-vue-router
|
||||||
// ⚠️ Vue must be placed after VueRouter()
|
// ⚠️ Vue must be placed after VueRouter()
|
||||||
vueRouter: vueRouter({
|
vueRouter: vueRouter({
|
||||||
exclude: ['**/__*', '**/__*/**/*'],
|
|
||||||
extensions: ['.page.vue', '.page.md'],
|
|
||||||
getRouteName: (routeNode) => getPascalCaseRouteName(routeNode),
|
|
||||||
logs: false,
|
|
||||||
routesFolder: 'src/pages',
|
routesFolder: 'src/pages',
|
||||||
|
extensions: ['.page.vue', '.page.md'],
|
||||||
|
exclude: ['**/__*', '**/__*/**/*'],
|
||||||
|
getRouteName: (await import('unplugin-vue-router')).getPascalCaseRouteName,
|
||||||
|
beforeWriteFiles(rootRoute) {
|
||||||
|
for (/* 深度优先遍历 */ const route of rootRoute.traverseDFS()) {
|
||||||
|
route.addToMeta({ _: route.fullPath });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
logs: true,
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user