Hexta AIHexta AI

Next.js

Use Hexta MDX with Next.js

Setup

Set up Hexta MDX for your Next.js application.

Installation

npm i hexta-mdx hexta-core @types/mdx

Create the configuration file:

source.config.ts
import { defineDocs, defineConfig } from 'hexta-mdx/config';

export const docs = defineDocs({
  dir: 'content/docs',
});

export default defineConfig();

Add the plugin to Next.js config:

next.config.mjs
import { createMDX } from 'hexta-mdx/next';

/** @type {import('next').NextConfig} */
const config = {
  reactStrictMode: true,
};

const withMDX = createMDX({
  // customize the config file path
  // configPath: "source.config.ts"
});

export default withMDX(config);

ESM Only

Hexta MDX is ESM-only, it's recommended to use next.config.mjs for accurate ESM resolution.

For TypeScript config file, it requires Native Node.js TypeScript Resolver, you can see Next.js docs for details.

Setup an import alias (recommended):

tsconfig.json
{
  "compilerOptions": {
    "paths": {
      "collections/*": ["./.source/*"]
    }
  }
}

Integrate with Hexta AI

You can create a lib/source.ts file and obtain Hexta AI source from the docs collection output.

lib/source.ts
import { docs } from 'collections/server';
import { loader } from 'hexta-core/source';

export const source = loader({
  baseUrl: '/docs',
  source: docs.toHextaSource(),
});

The .source folder will be generated when you run next dev or next build.

Done

You can now write content in content/docs folder.

What is Next?

How is this guide?