Raw
1 import createMDX from "@next/mdx"
2 import bundleAnalyzer from "@next/bundle-analyzer"
3 import rehypeMdxCodeProps from "rehype-mdx-code-props"
4 import rehypeSlug from "rehype-slug"
5 import {
6 brokenLinkCheckerPlugin,
7 crossProjectLinksPlugin,
8 validateHighlightsPlugin,
9 } from "remark-rehype-plugins"
10 import path from "path"
11 import { catchBadRedirects } from "build-scripts"
12 import { crossProjectLinksOptions } from "./utils/cross-project-links-options.mjs"
13
14 /** @type {import('next').NextConfig} */
15 const nextConfig = {
16 // Configure `pageExtensions` to include MDX files
17 pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
18 basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/api",
19 outputFileTracingRoot: new URL("../../", import.meta.url).pathname,
20 outputFileTracingExcludes: {
21 "*": ["../**/.open-next/**", "../!(api-reference)/.next/**"],
22 },
23 webpack: (config) => {
24 config.ignoreWarnings = [{ module: /node_modules\/keyv\/src\/index\.js/ }]
25
26 return config
27 },
28 transpilePackages: ["docs-ui", "docs-utils"],
29 experimental: {
30 optimizePackageImports: ["docs-utils"],
31 },
32 async redirects() {
33 return catchBadRedirects([
34 {
35 source: "/api/download/:path",
36 destination: "/download/:path",
37 permanent: true,
38 },
39 ])
40 },
41 async rewrites() {
42 const markdownAccept = [
43 {
44 type: "header",
45 key: "Accept",
46 value: ".*(text/markdown|text/plain).*",
47 },
48 ]
49
50 return {
51 beforeFiles: [
52 // Explicit `.md` (and `/index.md`, `/index.html.md`) suffixes for the
53 // area index.
54 {
55 source: "/:area(store|admin).md",
56 destination: "/md-content/:area",
57 },
58 {
59 source: "/:area(store|admin)/index.md",
60 destination: "/md-content/:area",
61 },
62 {
63 source: "/:area(store|admin)/index.html.md",
64 destination: "/md-content/:area",
65 },
66 // Explicit `.md` suffixes for nested paths (sections, tags, operations,
67 // schemas).
68 {
69 source: "/:area(store|admin)/:rest*/index.html.md",
70 destination: "/md-content/:area/:rest*",
71 },
72 {
73 source: "/:area(store|admin)/:rest*/index.md",
74 destination: "/md-content/:area/:rest*",
75 },
76 {
77 source: "/:area(store|admin)/:rest*.md",
78 destination: "/md-content/:area/:rest*",
79 },
80 // Content negotiation: serve Markdown for text/markdown | text/plain.
81 {
82 source: "/:area(store|admin)/:rest*",
83 has: markdownAccept,
84 destination: "/md-content/:area/:rest*",
85 },
86 {
87 source: "/:area(store|admin)",
88 has: markdownAccept,
89 destination: "/md-content/:area",
90 },
91 ],
92 }
93 },
94 }
95
96 const withMDX = createMDX({
97 options: {
98 rehypePlugins: [
99 [
100 brokenLinkCheckerPlugin,
101 {
102 crossProjects: {
103 docs: {
104 projectPath: path.resolve("..", "book"),
105 },
106 resources: {
107 projectPath: path.resolve("..", "resources"),
108 hasGeneratedSlugs: true,
109 },
110 ui: {
111 projectPath: path.resolve("..", "ui"),
112 },
113 "user-guide": {
114 projectPath: path.resolve("..", "user-guide"),
115 },
116 cloud: {
117 projectPath: path.resolve("..", "cloud"),
118 },
119 },
120 },
121 ],
122 [crossProjectLinksPlugin, crossProjectLinksOptions],
123 [
124 rehypeMdxCodeProps,
125 {
126 tagName: "code",
127 },
128 ],
129 [validateHighlightsPlugin, { verbose: false }],
130 [rehypeSlug],
131 ],
132 development: process.env.NODE_ENV === "development",
133 },
134 })
135
136 const withBundleAnalyzer = bundleAnalyzer({
137 enabled: process.env.ANALYZE_BUNDLE === "true",
138 })
139
140 export default withMDX(withBundleAnalyzer(nextConfig))