Skip to content
On this page

Vite Plugin

Use Routeflux inside Vite.

Minimal setup

ts
import { defineConfig } from "vite";
import { crawlerPlugin } from "@routeflux/vite-plugin";

export default defineConfig({
  plugins: [crawlerPlugin()],
});
ts
import { defineConfig } from "vite";
import { crawlerPlugin } from "@routeflux/vite-plugin";

export default defineConfig({
  server: {
    origin: "https://example.com",
  },
  plugins: [
    crawlerPlugin({
      baseUrl: "https://example.com",
      output: ["routes.json", "sitemap.xml"],
    }),
  ],
});

Options

OptionTypeDescription
enabledbooleanDisables the plugin entirely when set to false.
baseUrlstringBase URL used for build crawling and sitemap generation.
rootDirstringProject root used for adapter detection and static extraction. Defaults to process.cwd().
outputstring | string[]Output targets. Supported values are routes.json and sitemap.xml.
crawlCrawlOptionsRuntime crawl options like maxDepth, maxPages, and interactionDelay.
crawlerCrawlerCustom crawler override.
generatorsGenerator[]Custom generator overrides registered through the container.
adapterRouteAdapterExplicit adapter override.
adaptersRouteAdapter[]Additional adapter candidates checked before the built-in defaults.
pluginsPlugin[]Routeflux plugins that can reconfigure services through the container.

Lifecycle

configureServer

  • waits for the Vite dev server to start listening
  • resolves the actual server URL from Vite
  • runs a crawl automatically
  • logs the discovered route count

closeBundle

  • runs after Vite has written build output
  • uses server.origin or baseUrl for crawling and output generation
  • writes selected outputs into build.outDir

Service orchestration

The plugin resolves services through the Routeflux container:

  • adapter detection and static extraction happen first
  • the crawler receives the adapter plus static routes
  • generators are registered in the container and then used to produce build outputs
  • plugins can replace or extend registered services before the crawl starts