> ## Documentation Index
> Fetch the complete documentation index at: https://better-router.bansal.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuration

> Plugin options, defaults, and the worker entrypoint.

```ts title="vite.config.ts" theme={null}
import { defineConfig } from "vite";
import { betterRouter } from "better-router/plugin";

export default defineConfig({
  plugins: [betterRouter()],
});
```

Every path below is optional to pass in. Defaults assume `srcDir: "src"`.

## Directories and files

| Option                   | Default                   | Purpose                                     |
| ------------------------ | ------------------------- | ------------------------------------------- |
| `srcDir`                 | `src`                     | Root of routes, middleware, and `worker.ts` |
| `routesDir`              | `src/routes`              | Pages and API routes                        |
| `middlewareDir`          | `src/middleware`          | Global Hono middleware                      |
| `workerEntry`            | `src/worker.ts`           | `defineWorker` handlers (Cloudflare)        |
| `markdown.componentsDir` | `src/components/markdown` | Auto-registered markdown / MDX components   |

`src/worker.ts` is optional. Node apps do not need it. If the file is missing, the plugin also looks at `src/config/worker.ts`.

## Runtime

| Option     | Default | Purpose                                                                    |
| ---------- | ------- | -------------------------------------------------------------------------- |
| `target`   | `auto`  | `cloudflare` when a Wrangler file exists, else `node`. Also `bun`, `deno`. |
| `ssr`      | `true`  | Default for pages that do not export `ssr`                                 |
| `islands`  | `true`  | Transform `with { island: "..." }` imports                                 |
| `basePath` | `/`     | Reserved; keep `/`                                                         |
| `react`    | `{}`    | Options forwarded to `@vitejs/plugin-react`                                |

You do not add `@vitejs/plugin-react` yourself — `betterRouter()` already includes it. Pass `react: { babel: ... }` if you need to.

## Markdown

`.md` / `.mdx` files in `routesDir` are pages. See [Markdown pages](/markdown).

```ts theme={null}
betterRouter({
  markdown: {
    componentsDir: "src/components/markdown",
    remarkPlugins: [],
    rehypePlugins: [],
    parse: async (file) => ({ html: render(file.content) }),
  },
});
```

| Field                                              | Purpose                                                        |
| -------------------------------------------------- | -------------------------------------------------------------- |
| `componentsDir`                                    | Folder of default-export React components mapped into MDX      |
| `remarkPlugins` / `rehypePlugins` / `recmaPlugins` | Compiler plugins (`remark-gfm` and `rehype-slug` are built in) |
| `parse`                                            | Custom HTML renderer (for example comark)                      |
| `compile`                                          | Full module override. Wins over `parse`                        |
