Raw
1 import mdx from "@next/mdx"
2 import path from "path"
3 import rehypeMdxCodeProps from "rehype-mdx-code-props"
4 import rehypeSlug from "rehype-slug"
5 import remarkDirective from "remark-directive"
6 import remarkFrontmatter from "remark-frontmatter"
7 import {
8 brokenLinkCheckerPlugin,
9 localLinksRehypePlugin,
10 cloudinaryImgRehypePlugin,
11 resolveAdmonitionsPlugin,
12 crossProjectLinksPlugin,
13 prerequisitesLinkFixerPlugin,
14 remarkAttachFrontmatterDataPlugin,
15 recmaInjectMdxDataPlugin,
16 validateHighlightsPlugin,
17 uiRehypePlugin,
18 } from "remark-rehype-plugins"
19 import bundleAnalyzer from "@next/bundle-analyzer"
20 import withExtractedTableOfContents from "@stefanprobst/rehype-extract-toc"
21 import { ExampleRegistry } from "./specs/examples.mjs"
22 import { ComponentSpecsIndex } from "./generated/components-index.mjs"
23
24 const withMDX = mdx({
25 extension: /\.mdx?$/,
26 options: {
27 rehypePlugins: [
28 [
29 brokenLinkCheckerPlugin,
30 {
31 crossProjects: {
32 docs: {
33 projectPath: path.resolve("..", "book"),
34 },
35 cloud: {
36 projectPath: path.resolve("..", "cloud"),
37 },
38 resources: {
39 projectPath: path.resolve("..", "resources"),
40 hasGeneratedSlugs: true,
41 },
42 api: {
43 projectPath: path.resolve("..", "api-reference"),
44 skipSlugValidation: true,
45 },
46 "user-guide": {
47 projectPath: path.resolve("..", "user-guide"),
48 },
49 },
50 },
51 ],
52 [
53 crossProjectLinksPlugin,
54 {
55 baseUrl: process.env.NEXT_PUBLIC_BASE_URL,
56 projectUrls: {
57 docs: {
58 url: process.env.NEXT_PUBLIC_DOCS_URL,
59 path: "",
60 },
61 resources: {
62 url: process.env.NEXT_PUBLIC_RESOURCES_URL,
63 },
64 cloud: {
65 url: process.env.NEXT_PUBLIC_CLOUD_URL,
66 },
67 api: {
68 url: process.env.NEXT_PUBLIC_API_URL,
69 },
70 "user-guide": {
71 url: process.env.NEXT_PUBLIC_USER_GUIDE_URL,
72 },
73 },
74 useBaseUrl:
75 process.env.NODE_ENV === "production" ||
76 process.env.VERCEL_ENV === "production" ||
77 !!process.env.CLOUDFLARE_ENV,
78 },
79 ],
80 [localLinksRehypePlugin],
81 [
82 rehypeMdxCodeProps,
83 {
84 tagName: "code",
85 },
86 ],
87 [validateHighlightsPlugin, { verbose: false }],
88 [rehypeSlug],
89 [
90 cloudinaryImgRehypePlugin,
91 {
92 cloudinaryConfig: {
93 cloudName: process.env.CLOUDINARY_CLOUD_NAME || "",
94 flags: ["fl_lossy", "f_auto"],
95 resize: {
96 action: "pad",
97 aspectRatio: "16:9",
98 },
99 roundCorners: 16,
100 },
101 },
102 ],
103 [
104 prerequisitesLinkFixerPlugin,
105 {
106 checkLinksType: "value",
107 },
108 ],
109 [withExtractedTableOfContents],
110 [
111 uiRehypePlugin,
112 {
113 exampleRegistry: ExampleRegistry,
114 specsIndex: ComponentSpecsIndex,
115 specsBaseUrl: process.env.UI_SPECS_R2_BASE_URL,
116 },
117 ],
118 ],
119 remarkPlugins: [
120 [remarkFrontmatter],
121 [remarkDirective],
122 [resolveAdmonitionsPlugin],
123 [remarkAttachFrontmatterDataPlugin],
124 ],
125 recmaPlugins: [[recmaInjectMdxDataPlugin]],
126 jsx: true,
127 },
128 })
129
130 /** @type {import('next').NextConfig} */
131 const nextConfig = {
132 // Configure `pageExtensions` to include MDX files
133 pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
134
135 transpilePackages: ["docs-ui"],
136 basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/ui",
137 outputFileTracingRoot: new URL("../../", import.meta.url).pathname,
138 outputFileTracingIncludes: {
139 "/md\\-content/\\[\\[\\.\\.\\.slug\\]\\]": [
140 "./app/**/*.mdx",
141 "./specs/**/*",
142 "./examples/**/*",
143 ],
144 },
145 outputFileTracingExcludes: {
146 "*": [
147 "node_modules/@medusajs/icons",
148 "../**/.open-next/**",
149 "../!(ui)/.next/**",
150 ],
151 },
152 experimental: {
153 optimizePackageImports: ["@medusajs/icons", "@medusajs/ui"],
154 },
155 rewrites: async () => {
156 return {
157 beforeFiles: [
158 {
159 source: "/index.html.md",
160 destination: "/md-content",
161 },
162 {
163 source: "/index.md",
164 destination: "/md-content",
165 },
166 {
167 source: "/:path*/index.html.md",
168 destination: "/md-content/:path*",
169 },
170 {
171 source: "/:path*/index.md",
172 destination: "/md-content/:path*",
173 },
174 {
175 source: "/:path*.md",
176 destination: "/md-content/:path*",
177 },
178 {
179 source: "/:first((?!md-content)[^/]+)/:rest*/",
180 has: [
181 {
182 type: "header",
183 key: "Accept",
184 value: ".*(text/markdown|text/plain).*",
185 },
186 ],
187 destination: "/md-content/:first/:rest*",
188 },
189 {
190 source: "/",
191 has: [
192 {
193 type: "header",
194 key: "Accept",
195 value: ".*(text/markdown|text/plain).*",
196 },
197 ],
198 destination: "/md-content",
199 },
200 {
201 source: "/:first((?!md-content)[^/]+)/:rest*",
202 has: [
203 {
204 type: "header",
205 key: "Accept",
206 value: ".*(text/markdown|text/plain).*",
207 },
208 ],
209 destination: "/md-content/:first/:rest*",
210 },
211 ],
212 }
213 },
214 }
215
216 const withBundleAnalyzer = bundleAnalyzer({
217 enabled: process.env.ANALYZE === "true",
218 })
219
220 export default withMDX(withBundleAnalyzer(nextConfig))