@farming-labs/next

中文文档
0.2.146发布于 2026/11/14MITTypeScriptES Module近 30 天下载 2.2万

Next.js adapter for @farming-labs/docs — MDX config wrapper

原始使用文档
文档目录9 节
  1. What this package does
  2. Install
  3. Minimal setup
  4. Extending MDX compilation
  5. Page metadata transport
  6. Main entrypoints
  7. Requirements
  8. Learn more
  9. License

@farming-labs/next

The Next.js App Router adapter for @farming-labs/docs.

It connects the shared docs configuration and theme to Next.js, compiles Markdown and MDX, generates the standard docs routes, and provides Next-native runtime helpers for documentation APIs, API references, MCP, and changelogs.

What this package does

  • Wraps next.config.ts with the Farming Labs MDX and routing integration
  • Generates missing docs layouts, API routes, MCP routes, and enabled feature routes
  • Adds machine-readable Markdown, agent discovery, sitemap, and llms.txt rewrites
  • Provides App Router layout, metadata, API-reference, and changelog helpers
  • Preserves user-authored files and existing Next.js configuration

The shared config and CLI live in @farming-labs/docs. React UI, MDX components, providers, and theme CSS live in @farming-labs/theme.

Install

The CLI can add docs to an existing Next.js project:

npx @farming-labs/docs@latest init

For manual installation:

npm install @farming-labs/docs @farming-labs/next @farming-labs/theme

Minimal setup

Create docs.config.ts with defineDocs(), then wrap the Next.js config:

// next.config.ts
import { withDocs } from "@farming-labs/next/config";

export default withDocs();

Existing Next.js configuration can be passed directly:

export default withDocs({
  reactStrictMode: true,
});

Import the selected theme in your global stylesheet:

@import "tailwindcss";
@import "@farming-labs/theme/default/css";

Write documentation pages under app/docs/ or src/app/docs/. The CLI also adds the root RootProvider, generated docs layout, and server routes needed for a complete setup.

Extending MDX compilation

Set mdx in docs.config.ts and pass the live config to withDocs. Plugin module names and paths with JSON options work with both Webpack and Turbopack:

export default defineDocs({
  entry: "docs",
  mdx: {
    remarkPlugins: ["remark-directive", "./lib/remark-docs.mjs"],
    rehypePlugins: [["rehype-external-links", { target: "_blank" }]],
  },
});
import { withDocs } from "@farming-labs/next/config";
import docsConfig from "./docs.config";

export default withDocs({}, docsConfig);

Install the plugins in your application. Paths starting with ./ or ../ resolve from the application root. Extra plugins run after the built-in plugins in their respective phase; frontmatter, heading IDs, TOC, Markdown alternate links, and syntax highlighting remain enabled. Put callbacks and other non-JSON configuration inside a local plugin module.

For a migration with its own highlighter, set mdx.codeHighlighter to that plugin's module name or [module, options] tuple. This replaces only the default code-highlighting step, so code is highlighted once. The custom plugin owns its theme and code-block behavior. Omitting mdx keeps the existing defaults. These hooks do not configure Fumadocs collections or replace its source loader.

The third-argument withDocs(nextConfig, docsConfig, { mdx }) form is deprecated and still works. Setting mdx in both places throws.

The built-in highlighter uses Shiki's Oniguruma engine during compilation. A custom highlighter can import @farming-labs/next/mdx-plugins/rehype-code to keep that default while configuring themes and transformers. Passing engine: "js" explicitly selects Shiki's JavaScript engine.

Page metadata transport

Production builds send title, description, reading time, dates, and structured data with each compatible Markdown/MDX page. The shared layout keeps navigation and theme settings. This changes the data boundary without changing the rendered page markup or the theme API.

Automatic selection applies to ordinary file routes using the standard generated layout and MDX provider. Customized layouts, MDX providers, compiler extensions, components.wrapper, development, localized layouts, multiple docs roots, custom content directories, Next.js basePath, nested layouts/templates, dynamic/group/parallel routes, and authored MDX exports keep the existing site-wide metadata path. Code fences containing exports remain eligible. Older installed core or theme packages without the boundary support also keep the existing path.

To retain site-wide metadata explicitly:

export default withDocs({}, undefined, { pageMetadata: "site" });

The default is pageMetadata: "auto". Both transports use the same metadata builder and page component. Custom compiler extensions retain the existing transport. The boundary subpaths are internal compiler integration points, not application component APIs.

Main entrypoints

EntrypointPurpose
@farming-labs/next/configwithDocs() Next.js configuration wrapper
@farming-labs/next/layoutApp Router docs layout and metadata helpers
@farming-labs/next/apiDocs API and MCP route handlers
@farming-labs/next/api-referenceGenerated API-reference routes and pages
@farming-labs/next/changelogGenerated changelog page helpers

Requirements

  • Next.js 16 or newer
  • React and React DOM 19.2 or newer
  • @farming-labs/docs 0.2.121 or newer and @farming-labs/theme

Learn more

License

MIT

版本与发布记录

@farming-labs/next 共发布 379 个版本,首次发布于 2026/02/17;过去 12 个月发布了 379 个版本。

版本发布日期距今
0.2.146latest2026/11/14今天
0.2.1452026/11/131 天前
0.2.1442026/11/131 天前
0.2.1432026/11/068 天前
0.2.1422026/11/068 天前
0.2.1412026/11/059 天前

其他发布通道:perf → 0.2.133-perf.1,beta → 0.2.139-beta.1。

关于 @farming-labs/next 的常见问题

@farming-labs/next 是什么?

Next.js adapter for @farming-labs/docs — MDX config wrapper

如何安装 @farming-labs/next?

在项目目录运行 npm install @farming-labs/next,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:next(>=16.0.0)、react(>=19.2.0)、react-dom(>=19.2.0)、@farming-labs/docs(>=0.2.121 || ^0.2.133-perf.0)、@farming-labs/theme(>=0.0.1 || ^0.2.133-perf.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@farming-labs/next 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@farming-labs/next 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@farming-labs/next 可以商用吗?

@farming-labs/next 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@farming-labs/next 的下载量有多少?

根据 npm 官方下载统计,@farming-labs/next 在 2026/10/15 – 2026/11/13 这 30 天内被下载 22,359 次,日均约 745 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@farming-labs/next 还在维护吗?

最新版本 0.2.146 发布于 2026/11/14(今天);至今共发布 379 个版本,其中过去 12 个月发布了 379 个;首次发布于 2026/02/17。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。