npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

vite-plugin-web-routes

v0.1.3

Published

Vite plugin that generates React Router v6 routes from your filesystem. Place files named PAGE.tsx, LAYOUT.tsx, BOUNDARY.tsx or ERROR.tsx and get a fully typed routes.ts with zero manual configuration.

Readme

vite-plugin-web-routes

Plugin de Vite que genera rutas para React Router v6+ a partir del filesystem.

El archivo de rutas se escribe en disco en cada inicio y ante cada cambio — sin scanning en runtime.


Instalación

// vite.config.ts
import { webRoutes } from "vite-plugin-web-routes";

export default defineConfig({
  plugins: [
    webRoutes({
      moduleId: "~react-pages", // Alias Import default: @web/routes.jsx
      dirs: [{ dir: "src/pages", route: "" }],
    }),
  ],
});
// main.tsx
import routes from "./routes";
import { createBrowserRouter, RouterProvider } from "react-router-dom";

createRoot(document.getElementById("root")!).render(
  <RouterProvider router={createBrowserRouter(routes)} />,
);

Opciones

webRoutes({
  root?:       string          // cwd por defecto
  moduleFile?: string          // ruta del archivo generado — default ".web/routes.jsx"
  moduleId?:   string          // alias del archivo — default "@web/routes.jsx"
  routeBase?:  string          // prefijo global de rutas
  dirs:        DirOpt[]        // directorios de páginas (requerido)
  allLazy?:    boolean         // todas las páginas lazy — default false
  allowWrap?:  boolean         // false, No hablitado
  allowLayout?:boolean         // true, Hablitado
  exclude?:    string[]        // directorios a ignorar — default ["node_modules", ".git"]
  include?:    string[]        // patrones adicionales de inclusión
  roleMapping?: RoleMapping    // mapa de nombres de archivo → rol (ver más abajo)
})

DirOpt

{
  dir:    string   // ruta relativa al root
  route:  string   // prefijo de ruta — "" para raíz "/"
  skip?:  boolean  // excluye el directorio completamente
  lazy?:  boolean  // todas las páginas de este dir son lazy
}

Archivos especiales

| Archivo | Rol | Lazy | Descripción | | ------------------- | ------------ | ----- | ------------------------------------------- | | PAGE.tsx | PAGE | false | Componente de la página | | PAGE.lazy.tsx | PAGE | true | Igual, cargado con React.lazy() | | ERROR.tsx | PAGE_ERROR | false | errorElement del route de la página | | ERROR.lazy.tsx | PAGE_ERROR | true | Igual, cargado con React.lazy() | | LAYOUT.tsx | LAYOUT | false | Wrapper con <Outlet /> — crea anidamiento | | LAYOUT.lazy.tsx | LAYOUT | true | Igual, cargado con React.lazy() | | BOUNDARY.tsx | LAYOUT_ERROR | false | errorElement del route del layout | | BOUNDARY.lazy.tsx | LAYOUT_ERROR | true | Igual, cargado con React.lazy() | | ROOT.tsx | WRAP | false | Wrapper con <Outlet /> — crea anidamiento | | CATCH.tsx | WRAP_ERROR | false | errorElement del route del wrapper |

ERROR vs BOUNDARY

src/pages/
  LAYOUT.tsx      ← layout raíz
  BOUNDARY.tsx    ← errorElement del layout (captura errores de cualquier hijo)
  PAGE.tsx        ← página raíz
  ERROR.tsx       ← errorElement de la página (solo captura errores de PAGE)
  • BOUNDARY reemplaza el layout completo (cabecera, sidebar desaparecen).
  • ERROR reemplaza solo el contenido de la página; el layout sigue visible.

Parámetros de URL

Los directorios con [param] generan segmentos dinámicos :param:

src/pages/user/[id]/PAGE.tsx     →  /user/:id
src/pages/[category]/[slug]/PAGE.tsx  →  /:category/:slug
src/pages/$category/$slug/PAGE.tsx  →  /:category/:slug
src/pages/[...]/PAGE.tsx  →  /*
src/pages/[]/PAGE.tsx  →  /*
src/pages/$$/PAGE.tsx  →  /*
// user/[id]/PAGE.tsx
import { useParams } from "react-router-dom";

export default function UserPage() {
  const { id } = useParams<{ id: string }>();
  return <p>Usuario: {id}</p>;
}

Reglas de routing

Con LAYOUT → rutas anidadas

src/pages/
  LAYOUT.tsx      →  { path: "/", element: <Layout> }
  PAGE.tsx        →  { index: true, element: <Page> }
  about/PAGE.tsx  →  { path: "about", element: <About> }
/           → Layout > Page (index)
/about      → Layout > About

Sin LAYOUT → rutas planas

src/pages/
  PAGE.tsx        →  { path: "/", element: <Page> }
  about/PAGE.tsx  →  { path: "about", element: <About> }

Multi-root

dirs: [
  { dir: "src/pages", route: "" }, // /
  { dir: "src/admin", route: "admin" }, // /admin/*
];

Cada directorio es un módulo de rutas aislado. Todos se combinan en el array final.


Lazy loading

Hay tres formas de marcar páginas como lazy:

// 1. Toda la aplicación
webRoutes({ allLazy: true, dirs: [...] })

// 2. Por directorio
dirs: [{ dir: 'src/pages', route: '', lazy: true }]

// 3. Por archivo — sufijo .lazy en el nombre
// src/pages/blog/intro/PAGE.lazy.tsx

Los tres niveles se combinan: allLazy || dir.lazy || file.lazy.


roleMapping

Permite extender o redefinir qué nombres de archivo se reconocen como roles:

webRoutes({
  dirs: [{ dir: "src/pages", route: "" }],
  roleMapping: {
    // alias: INDEX.tsx → mismo rol que PAGE
    INDEX: { role: "PAGE", lazy: false },
    // alias: CATCH.tsx → mismo rol que BOUNDARY
    CATCH: { role: "BOUNDARY", lazy: false },
  },
});

El mapping del usuario se fusiona con el mapping por defecto. Los roles disponibles son: PAGE, LAYOUT, ERROR, BOUNDARY.


Output

El archivo generado es TypeScript/JavaScript estático:

// src/routes.ts — generado automáticamente
import { lazy, createElement } from "react";
import type { RouteObject } from "react-router-dom";

import _pages_LAYOUT from "./pages/LAYOUT.tsx";
import _pages_PAGE from "./pages/PAGE.tsx";
const _pages_blog_PAGE = lazy(() => import("./pages/blog/PAGE.lazy.tsx"));

const routes: RouteObject[] = [
  {
    path: "/",
    element: createElement(_pages_LAYOUT),
    errorElement: createElement(_pages_BOUNDARY),
    children: [
      { index: true, element: createElement(_pages_PAGE) },
      { path: "blog", element: createElement(_pages_blog_PAGE) },
    ],
  },
];

export default routes;

Principios

  • El filesystem es la fuente de verdad.
  • Sin runtime — las rutas se compilan al iniciar Vite.
  • Output determinista en disco, commitable al repositorio.
  • Multi-root: cada dir es un módulo de rutas aislado.

Routes are compiled, not declared.