vite-plugin-remix-routes
Version:
Use Remix routing in your Vite project
64 lines (59 loc) • 2.29 kB
TypeScript
import { Plugin } from 'vite';
import { AppConfig } from '@remix-run/dev/dist/config';
declare type RequireOnly<Object, Keys extends keyof Object> = Omit<Object, Keys> & Required<Pick<Object, Keys>>;
interface Context {
prefix: string;
dataRouterCompatible?: boolean;
importMode?: (route: Route) => "sync" | "async";
}
declare function stringifyRoutes(routes: Route[], context: Context): {
routesString: string;
componentsString: string;
};
declare type RemixOptions = Pick<AppConfig, "appDirectory" | "routes" | "ignoredRouteFiles">;
declare type GetRouteOptions = Omit<PluginOptions, "importMode"> & RequireOnly<RemixOptions, "appDirectory">;
/**
* See `readConfig` in @remix-run/dev/config.ts
*/
declare function getRoutes(options: GetRouteOptions): Promise<Route[]>;
interface Route {
id: string;
file: string;
path: string;
index: boolean;
children: Route[];
}
interface Options extends PluginOptions, RemixOptions {
}
interface PluginOptions {
/**
* Set this to `false` if you're not using a router compatible with the data APIs
* released in react-router 6.4.
* https://reactrouter.com/en/main/routers/picking-a-router#using-v64-data-apis
*
* @default true
*/
dataRouterCompatible?: boolean;
/**
* NOTE: This option only works if `dataRouterCompatible` is set to `false`.
*
* A function that receives a `Route` to determine if the route's component
* should be imported synchronously or asynchronously.
*
* @default () => "sync"
*/
importMode?: (route: Route) => "async" | "sync";
/**
* NOTE: This option only works if `dataRouterCompatible` is set to `false`. You should use an `ErrorBoundary` component instead.
*
* A function that receives a `Route` to determine if it should be a 404 route. (`path="*"`)
* By default this matches the same 404 file as Remix does.
* Keep in mind this only receives top level routes, so you can't mark nested routes
* as 404 routes.
*
* @default (route) => route.id === "routes/404"
*/
is404Route?: (route: Route) => boolean;
}
declare function plugin(options?: Options): Plugin;
export { Options, PluginOptions, Route, plugin as default, getRoutes, stringifyRoutes };