@onderwijsin/nuxt-directus-prerenderer

Prerender Nuxt routes from Directus collection data.
817
Install
npm install @onderwijsin/nuxt-directus-prerenderer
Latest Version:0.3.1
Vue:3
License:MIT
Last Updated:Oct 18, 2026
Links: GitHub  ·  npm
Maintainer: remihuigen

@onderwijsin/nuxt-directus-prerenderer

Prerender routes discovered from Directus collections during Nuxt builds. The module fetches configured records during module setup, maps them to application paths, deduplicates the result, and adds the routes through Nuxt's prerender:routes hook.

Installation

pnpm add @onderwijsin/nuxt-directus-prerenderer

Install the shared config module when using executable mappers or fetchers:

pnpm add @onderwijsin/nuxt-directus-config
export default defineNuxtConfig({
  modules: ["@onderwijsin/nuxt-directus-config", "@onderwijsin/nuxt-directus-prerenderer"]
});

Configuration

Collection configuration belongs in directus.config.ts when it uses functions:

import { defineDirectusConfig } from "@onderwijsin/nuxt-directus-config/config";

export default defineDirectusConfig({
  instance: { baseUrl: "https://cms.example.com", proxyToken: "build-token" },
  collections: [
    {
      collection: "pages",
      sitemap: false,
      prerender: {
        fields: ["parent.path", "slug"],
        filter: { status: { _eq: "published" } },
        mapper: (page) => `${page.parent.path}/${page.slug}`
      }
    }
  ]
});

mapper is the recommended way to build composite routes. It may return a route, multiple routes, or null/undefined to omit an item. A declarative field map is available for direct permalink fields:

prerender: {
  fields: ["permalink"],
  fieldmap: { route: "permalink" }
}

The mapper takes precedence over fieldmap. Routes must be paths beginning with /, including /. Invalid mapped values are omitted.

Options

Option Default Description
directusPrerenderer.enabled true Enables the module.
directusPrerenderer.instance {} Module-owned build-time Directus baseUrl and optional proxyToken.
directusPrerenderer.collections [] Serializable collection overrides.
directusPrerenderer.includeStaticSitemapUrls false Adds static URLs from directusSitemaps.static or shared sitemaps.static.
directusPrerenderer.queryLimit 100 Page size for the default Directus fetcher.
directusPrerenderer.failureMode "best-effort" Omits failed collections or aborts with "hard-failure".

Module-local collection overrides may define fields, filter, and fieldmap; executable mapper and fetcher functions must remain in directus.config.ts.

The shared directus.config.ts prerenderer options provide defaults for the module. Explicit directusPrerenderer Nuxt module options take precedence over those shared defaults.

The default fetcher uses directusPrerenderer.instance (falling back to the shared instance in directus.config.ts) and paginates with queryLimit. Custom fetchers receive { collection, fields, filter }, return an array of items or route strings, and own their pagination. The module creates a build-time Directus SDK client because useDirectusServer requires a Nitro request event and runtime server context; neither is available while Nuxt setup discovers prerender routes. Successful setup fetches are shared between Directus build-time modules through the module-utils setup cache. Sitemap source fetching is runtime behavior and is not cached by this module.

Sitemap XML prerendering remains controlled by directusSitemaps.prerenderSitemaps; this module only adds content routes.

Related Packages

@onderwijsin/nuxt-directus-client

Server-safe Directus REST integration for Nuxt applications.

3,264 0
@onderwijsin/nuxt-turnstile

Nuxt Turnstile integration with client helpers and server-side validation.

2,924 0
@onderwijsin/nuxt-theme-customizer

Nuxt module for runtime theme selection and custom color editing in Nuxt UI.

2,719 0
@onderwijsin/nuxt-module-utils

Shared runtime and Nuxt module utilities for Onderwijs in modules.

2,622 0
@onderwijsin/nuxt-newsletter-signup

Provider-independent newsletter signup endpoint for Nuxt.

2,353 0

Version History

Version Released Vue License
0.3.1 ^3.0 MIT
0.3.0 ^3.0 MIT
0.2.3 ^3.0 MIT
0.2.2 ^3.0 MIT
0.2.1 ^3.0 MIT