0.0.13 • Published 12 months ago

vite-plugin-lazy-routes v0.0.13

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

vite-plugin-lazy-routes

Use Remix lazy flat-route routing in your Vite project.

Plugin config

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import lazyRoutes from "vite-plugin-lazy-routes";

export default defineConfig({
  plugins: [react(), lazyRoutes()],
});

With options:

lazyRoutes({
  /* options here */
});

Options

appDirectory

https://remix.run/docs/en/v1/api/conventions#appdirectory

  • Optional
  • Type: string
  • Default: path.join(process.cwd(), "app")

An absolute path to the folder containing the routes folder.

ignoredRouteFiles

  • Optional
  • Type: string[]

https://remix.run/docs/en/v1/api/conventions#ignoredroutefiles

This is an array of globs (via minimatch) that Remix will match to files while reading your app/routes directory. If a file matches, it will be ignored rather that treated like a route module. This is useful for ignoring dotfiles (like .DS_Store files) or CSS/test files you wish to colocate.

Usage

import lazyRoutes from "virtual:lazy-routes";

Example

import { render } from "react-dom";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import lazyRoutes from "virtual:lazy-routes";

// Note: This example only works with react-router >= 6.4
const router = createBrowserRouter([
  {
    path: "/",
    children: lazyRoutes,
    // You can add your own `element`, `errorElement`, `loader`, ...
  },
]);

render(
  <RouterProvider router={router}>
    <App />
  </RouterProvider>,
  document.querySelector("#app")
);

TypeScript

If you use TypeScript you can add the following to your vite-env.d.ts file.\ This will add types for the virtual:lazy-routes module.

/// <reference types="vite-plugin-lazy-routes/virtual" />

Similar projects

vite-plugin-pages

This project is inspired by vite-plugin-remix-routes

License

MIT

0.0.13

12 months ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.10

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago