@tys/vite-plugin-vue-page-route
Version:
A vite plugin for vue, auto generate route info by page
87 lines (83 loc) • 2.29 kB
TypeScript
import { Plugin } from 'vite';
/**
* plugin options
* @translate 插件配置
*/
interface PluginOption {
/**
* relative path to the directory to search for page files
* @default 'src/views'
*/
pageDir: string;
/**
* glob to match page files, based on the pageDir property
* @default [ '** /index.{vue,tsx,jsx}', '!** /components/**' ]
* - attention: there is no blank after '**'
* @link the detail syntax: https://github.com/micromatch/micromatch
*/
pageGlobs: string[];
/**
* relative path to the directory to generate the route declaration.
* @default 'src/typings/page-route.d.ts'
*/
routeDts: string;
/**
* relative path to the directory to generate the code of route module const
* @default src/router/modules
*/
routeModuleDir: string;
/**
* the extension to the directory to generate the code of route module const
* @default ts
*/
routeModuleExt: string;
/**
* the type declaretion of the generated route module item
* @default AuthRoute.Route
* @example
* ```ts
* const route: AuthRoute.Route = {
* name: 'home',
* path: '/home',
* component: 'self',
* meta: {
* title: 'home',
* singleLayout: 'basic'
* }
* }
* export default route;
* ```
*/
routeModuleType: string;
/**
* transform the route name
* @param name
*/
routeNameTansformer(name: string): string;
/**
* whether the route is lazy import
* @param name route name
* @example
* - the direct import
* ```ts
* import Home from './views/home/index.vue';
* ```
* - the lazy import
* ```ts
* const Home = import('./views/home/index.vue');
* ```
*/
lazyImport(name: string): boolean;
/**
* the route name, which is not tranfromed
* @param name
* @returns whether generate the route module, default is true
*/
onRouteModuleGenerate(name: string): boolean;
}
/**
* A vite plugin for vue, auto generate route info by page
* @param options plugin options
*/
declare function pageRoute(options?: Partial<PluginOption>): Plugin;
export { PluginOption, pageRoute as default };