Features
- More customisations via
source.config.ts
, a new config file for your content. - Introduced collections.
- Turbopack support.
- Build-time data validation support.
Migrate from v9
Refactor Imports
Refactor the import in next.config
.
From:
To:
Remove mdx-components.tsx
mdx-components.tsx
is no longer used. It now allows only MDX components passed from MDX
body's components
prop.
This encouraged explicit import of MDX components.
Previously, mdx-components.tsx
worked by injecting an import to every compiled Markdown/MDX file.
It's a little unnecessary because you can always import the components explicitly, or replace default HTML tags like img
from MDX body's components
prop.
Define Collections
Collection is now introduced on source config file (source.config.ts
).
It refers to a collection of files/content, like Markdown files, or JSON/YAML files.
Every collection has its own config, you can have customised Zod schema to validate its data, or collection-level MDX options for content collections.
You can create a source config file, and add the following:
defineDocs
declares two collections, one with doc
type that scans content files (e.g. md/mdx
), one with meta
type that scans meta files (e.g. json
).
Now you can generate types using fumadocs-mdx
command, it's recommended to set it as a postinstall
script.
Starting the development server, a .source
folder will be generated, it contains all parsed collections/files.
You can add it to .gitignore
, it will replace the old .map
file.
To access the collections, import them from the folder with their original name in source.config.ts
.
Now to integrate it with Fumadocs framework, change your source.ts
from:
to:
- we now recommend to export the output of
loader
directly as a single variable. - schema option is no longer defined in
source.ts
, it's handled bysource.config.ts
. - it takes two collections:
docs
(content) andmeta
(meta.json
). You can leavemeta
as an empty array if it is unused, so you can define only a collection fordocs
.
page.data
When using with loader
, you no longer need data.frontmatter
to access frontmatter data.
It is merged into the page.data
object.
MDX Options
Instead of passing them to next.config
file, define a global config in source.config.ts
:
Collection Schema
The schema
option of collection allow you to customise the validation schema, it accepts a Zod type.
For defineDocs
, see schema
.
Multiple Types
Same as before, you can call loader
multiple times for different types (e.g. for docs and blog).
and the corresponding source.config.ts
:
Further Readings
You can read the latest docs of Fumadocs MDX for details.
Written by
Fuma Nama
At
Sun Nov 24 2024