2025-07-27 10:05:37 -07:00
|
|
|
import { loader } from "fumadocs-core/source";
|
perf(docs): replace full lucide barrel import with explicit icon whitelist
Fixes #1241
The docs bundle was importing `{ icons }` from lucide-react, which pulls
the entire Lucide icon library (~1 400 SVGs, ~500 kB of JS) into the Next.js
docs bundle even though only nine icons are used in docs frontmatter and
meta.json files.
Replace with a hand-maintained DOCS_ICONS whitelist that imports only the
icons that are actually referenced (BookOpen, ClipboardCheck, Compass,
Container, Download, FlaskConical, Heart, Unplug, Wrench).
To add a new docs icon: import it from lucide-react and add it to the
DOCS_ICONS record. The icon() callback remains the same for callers.
2026-04-28 12:17:44 +08:00
|
|
|
import {
|
|
|
|
|
BookOpen,
|
|
|
|
|
ClipboardCheck,
|
|
|
|
|
Compass,
|
|
|
|
|
Container,
|
|
|
|
|
Download,
|
|
|
|
|
FlaskConical,
|
|
|
|
|
Heart,
|
|
|
|
|
Unplug,
|
|
|
|
|
Wrench,
|
|
|
|
|
} from "lucide-react";
|
2026-02-27 02:15:21 +05:30
|
|
|
import { createElement } from "react";
|
2026-02-27 15:45:48 -08:00
|
|
|
import { docs } from "@/.source/server";
|
2025-07-27 10:05:37 -07:00
|
|
|
|
perf(docs): replace full lucide barrel import with explicit icon whitelist
Fixes #1241
The docs bundle was importing `{ icons }` from lucide-react, which pulls
the entire Lucide icon library (~1 400 SVGs, ~500 kB of JS) into the Next.js
docs bundle even though only nine icons are used in docs frontmatter and
meta.json files.
Replace with a hand-maintained DOCS_ICONS whitelist that imports only the
icons that are actually referenced (BookOpen, ClipboardCheck, Compass,
Container, Download, FlaskConical, Heart, Unplug, Wrench).
To add a new docs icon: import it from lucide-react and add it to the
DOCS_ICONS record. The icon() callback remains the same for callers.
2026-04-28 12:17:44 +08:00
|
|
|
/** Explicit whitelist of Lucide icons used in docs frontmatter / meta.json.
|
|
|
|
|
* Importing the full `icons` barrel would pull every Lucide icon (~1 400 SVGs)
|
|
|
|
|
* into the docs bundle even though only a handful are referenced. Add new icons
|
|
|
|
|
* here as docs pages are added.
|
|
|
|
|
*/
|
|
|
|
|
const DOCS_ICONS: Record<string, React.ComponentType> = {
|
|
|
|
|
BookOpen,
|
|
|
|
|
ClipboardCheck,
|
|
|
|
|
Compass,
|
|
|
|
|
Container,
|
|
|
|
|
Download,
|
|
|
|
|
FlaskConical,
|
|
|
|
|
Heart,
|
|
|
|
|
Unplug,
|
|
|
|
|
Wrench,
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-22 02:24:13 -07:00
|
|
|
export const source = loader({
|
2025-07-27 10:05:37 -07:00
|
|
|
baseUrl: "/docs",
|
|
|
|
|
source: docs.toFumadocsSource(),
|
2026-02-27 02:15:21 +05:30
|
|
|
icon(icon) {
|
perf(docs): replace full lucide barrel import with explicit icon whitelist
Fixes #1241
The docs bundle was importing `{ icons }` from lucide-react, which pulls
the entire Lucide icon library (~1 400 SVGs, ~500 kB of JS) into the Next.js
docs bundle even though only nine icons are used in docs frontmatter and
meta.json files.
Replace with a hand-maintained DOCS_ICONS whitelist that imports only the
icons that are actually referenced (BookOpen, ClipboardCheck, Compass,
Container, Download, FlaskConical, Heart, Unplug, Wrench).
To add a new docs icon: import it from lucide-react and add it to the
DOCS_ICONS record. The icon() callback remains the same for callers.
2026-04-28 12:17:44 +08:00
|
|
|
if (icon && icon in DOCS_ICONS) return createElement(DOCS_ICONS[icon]);
|
2026-02-27 02:15:21 +05:30
|
|
|
},
|
2025-07-27 10:05:37 -07:00
|
|
|
});
|