#How to Fix: Qwik-city Static Build Not Generating dynamic MDX Routes

2 messages · Page 1 of 1 (latest)

celest kraken
#

Issue: When using the static HTML adapter with internationalized routes ([...lang]) and MDX files, npm run build.server fails to generate the expected language-specific HTML files (e.g., /en/example/index.html).

File Structure:

src/routes/[...lang]/example/index.mdx

Solution:

  1. Create a separate file (e.g., hack.ts) with the onStaticGenerate implementation:
import { StaticGenerateHandler } from "@builder.io/qwik-city";

export const onStaticGenerate: StaticGenerateHandler = () => {
  return {
    params: ["en", "es", "fr"],
  };
};
  1. Export the onStaticGenerate function in your MDX file:
export { onStaticGenerate } from "./hack"

This will properly generate the static HTML files for each language variant during build.

Build Command:

vite build --c adapters/static/vite.config.ts

Hope this saves someone else from debugging! 🚀

spare hatch
#

Nice! Want to make a cookbook entry for the docs?