Raw
1 import {
2 brokenLinkCheckerPlugin,
3 localLinksRehypePlugin,
4 prerequisitesLinkFixerPlugin,
5 recmaInjectMdxDataPlugin,
6 typeListLinkFixerPlugin,
7 validateHighlightsPlugin,
8 workflowDiagramLinkFixerPlugin,
9 } from "remark-rehype-plugins"
10
11 import bundleAnalyzer from "@next/bundle-analyzer"
12 import mdx from "@next/mdx"
13 import mdxPluginOptions from "./mdx-options.mjs"
14 import path from "node:path"
15 import { catchBadRedirects } from "build-scripts"
16
17 const withMDX = mdx({
18 extension: /\.mdx?$/,
19 options: {
20 rehypePlugins: [
21 [
22 brokenLinkCheckerPlugin,
23 {
24 rootBasePath: {
25 default: "app",
26 overrides: {
27 "/references": "",
28 },
29 },
30 hasGeneratedSlugs: true,
31 crossProjects: {
32 docs: {
33 projectPath: path.resolve("..", "book"),
34 },
35 ui: {
36 projectPath: path.resolve("..", "ui"),
37 },
38 "user-guide": {
39 projectPath: path.resolve("..", "user-guide"),
40 },
41 api: {
42 projectPath: path.resolve("..", "api-reference"),
43 skipSlugValidation: true,
44 },
45 cloud: {
46 projectPath: path.resolve("..", "cloud"),
47 },
48 },
49 },
50 ],
51 ...mdxPluginOptions.options.rehypePlugins,
52 [validateHighlightsPlugin, { verbose: false }],
53 [localLinksRehypePlugin],
54 [typeListLinkFixerPlugin],
55 [
56 workflowDiagramLinkFixerPlugin,
57 {
58 checkLinksType: "value",
59 },
60 ],
61 [
62 prerequisitesLinkFixerPlugin,
63 {
64 checkLinksType: "value",
65 },
66 ],
67 ],
68 remarkPlugins: mdxPluginOptions.options.remarkPlugins,
69 recmaPlugins: [[recmaInjectMdxDataPlugin]],
70 jsx: true,
71 },
72 })
73
74 /** @type {import('next').NextConfig} */
75 const nextConfig = {
76 // Configure `pageExtensions` to include MDX files
77 pageExtensions: ["js", "jsx", "mdx", "ts", "tsx"],
78
79 transpilePackages: ["docs-ui", "next-mdx-remote"],
80
81 basePath: process.env.NEXT_PUBLIC_BASE_PATH || "/resources",
82 async redirects() {
83 return catchBadRedirects([
84 {
85 source: "/admin-components/components/data-table",
86 destination: "/admin-components/guides/data-table",
87 permanent: true,
88 },
89 {
90 source: "/admin-components/components/forms",
91 destination: "/admin-components/guides/forms",
92 permanent: true,
93 },
94 {
95 source: "/admin-components/components/table",
96 destination: "/admin-components/guides/table",
97 permanent: true,
98 },
99 {
100 source: "/admin-components/layouts/single-column",
101 destination: "/admin-components/archive/single-column-layout",
102 permanent: true,
103 },
104 {
105 source: "/admin-components/layouts/two-column",
106 destination: "/admin-components/archive/two-column-layout",
107 permanent: true,
108 },
109 {
110 source: "/admin-components/components/layout-composer",
111 destination: "/admin-components/layouts/layout-composer",
112 permanent: true,
113 },
114 {
115 source: "/admin-components/components/container",
116 destination: "/admin-components/guides/container",
117 permanent: true,
118 },
119 {
120 source: "/admin-components/components/header",
121 destination: "/admin-components/guides/header",
122 permanent: true,
123 },
124 {
125 source: "/commerce-modules/order/relations-to-other-modules",
126 destination: "/commerce-modules/order/links-to-other-modules",
127 permanent: true,
128 },
129 {
130 source: "/commerce-modules/payment/relations-to-other-modules",
131 destination: "/commerce-modules/payment/links-to-other-modules",
132 permanent: true,
133 },
134 {
135 source: "/commerce-modules/api-key/relations-to-other-modules",
136 destination: "/commerce-modules/api-key/links-to-other-modules",
137 permanent: true,
138 },
139 {
140 source: "/commerce-modules/cart/relations-to-other-modules",
141 destination: "/commerce-modules/cart/links-to-other-modules",
142 permanent: true,
143 },
144 {
145 source: "/commerce-modules/fulfillment/relations-to-other-modules",
146 destination: "/commerce-modules/fulfillment/links-to-other-modules",
147 permanent: true,
148 },
149 {
150 source: "/commerce-modules/inventory/relations-to-other-modules",
151 destination: "/commerce-modules/inventory/links-to-other-modules",
152 permanent: true,
153 },
154 {
155 source: "/commerce-modules/region/relations-to-other-modules",
156 destination: "/commerce-modules/region/links-to-other-modules",
157 permanent: true,
158 },
159 {
160 source: "/commerce-modules/sales-channel/relations-to-other-modules",
161 destination: "/commerce-modules/sales-channel/links-to-other-modules",
162 permanent: true,
163 },
164 {
165 source: "/commerce-modules/stock-location/relations-to-other-modules",
166 destination: "/commerce-modules/stock-location/links-to-other-modules",
167 permanent: true,
168 },
169 {
170 source: "/commerce-modules/pricing/relations-to-other-modules",
171 destination: "/commerce-modules/pricing/links-to-other-modules",
172 permanent: true,
173 },
174 {
175 source: "/commerce-modules/product/relations-to-other-modules",
176 destination: "/commerce-modules/product/links-to-other-modules",
177 permanent: true,
178 },
179 {
180 source: "/commerce-modules/promotion/relations-to-other-modules",
181 destination: "/commerce-modules/promotion/links-to-other-modules",
182 permanent: true,
183 },
184 {
185 source: "/deployment/admin/vercel",
186 destination: "/deployment",
187 permanent: true,
188 },
189 {
190 source: "/recipes/integrate-ecommerce-stack",
191 destination: "/recipes/erp",
192 permanent: true,
193 },
194 {
195 source: "/contribution-guidelines/:path",
196 destination: `${process.env.NEXT_PUBLIC_BASE_URL}/learn/resources/contribution-guidelines/:path`,
197 permanent: true,
198 },
199 {
200 source: "/usage",
201 destination: `${process.env.NEXT_PUBLIC_BASE_URL}/learn/resources/usage`,
202 permanent: true,
203 },
204 {
205 source: "/plugins",
206 destination: "/integrations",
207 permanent: true,
208 },
209 {
210 source: "/resources",
211 destination: "/recipes",
212 permanent: true,
213 },
214 {
215 source: "/references/medusa-config",
216 destination: `${process.env.NEXT_PUBLIC_BASE_URL}/learn/configurations/medusa-config`,
217 permanent: true,
218 },
219 {
220 source: "/troubleshooting/workflow-errors",
221 destination: "/troubleshooting/workflow-errors/when-then",
222 permanent: true,
223 },
224 {
225 source: "/medusa-cli/commands/start-cluster",
226 destination: "/medusa-cli/commands/start",
227 permanent: true,
228 },
229 {
230 source: "/architectural-modules/:path*",
231 destination: "/infrastructure-modules/:path*",
232 permanent: true,
233 },
234 {
235 source: "/events-reference",
236 destination: "/references/events",
237 permanent: true,
238 },
239 {
240 source: "/commerce-modules/auth/events",
241 destination: "/references/auth/events",
242 permanent: true,
243 },
244 {
245 source: "/commerce-modules/cart/events",
246 destination: "/references/cart/events",
247 permanent: true,
248 },
249 {
250 source: "/commerce-modules/customer/events",
251 destination: "/references/customer/events",
252 permanent: true,
253 },
254 {
255 source: "/commerce-modules/fulfillment/events",
256 destination: "/references/fulfillment/events",
257 permanent: true,
258 },
259 {
260 source: "/commerce-modules/order/events",
261 destination: "/references/order/events",
262 permanent: true,
263 },
264 {
265 source: "/commerce-modules/payment/events",
266 destination: "/references/payment/events",
267 permanent: true,
268 },
269 {
270 source: "/commerce-modules/product/events",
271 destination: "/references/product/events",
272 permanent: true,
273 },
274 {
275 source: "/commerce-modules/region/events",
276 destination: "/references/region/events",
277 permanent: true,
278 },
279 {
280 source: "/commerce-modules/sales-channel/events",
281 destination: "/references/sales-channel/events",
282 permanent: true,
283 },
284 {
285 source: "/commerce-modules/user/events",
286 destination: "/references/user/events",
287 permanent: true,
288 },
289 {
290 source: "/storefront-development/cart",
291 destination: "/storefront-development/cart/create",
292 permanent: true,
293 },
294 {
295 source: "/storefront-development/customers",
296 destination: "/storefront-development/customers/register",
297 permanent: true,
298 },
299 {
300 source: "/storefront-development/products/categories",
301 destination: "/storefront-development/products/categories/list",
302 permanent: true,
303 },
304 {
305 source: "/storefront-development/products/collections",
306 destination: "/storefront-development/products/collections/list",
307 permanent: true,
308 },
309 {
310 source: "/storefront-development/products",
311 destination: "/storefront-development/products/list",
312 permanent: true,
313 },
314 {
315 source: "/deployment/medusa-application/railway",
316 destination: `${process.env.NEXT_PUBLIC_BASE_URL}/cloud/comparison`,
317 permanent: true,
318 },
319 ])
320 },
321 outputFileTracingRoot: new URL("../../", import.meta.url).pathname,
322 outputFileTracingExcludes: {
323 "*": [
324 "node_modules/@medusajs/icons",
325 "../**/.open-next/**",
326 "../!(resources)/.next/**",
327 ],
328 },
329 outputFileTracingIncludes: {
330 "/md\\-content/\\[\\[\\.\\.\\.slug\\]\\]": ["./app/**/*.mdx"],
331 "/md\\-content/references/**": ["./references/**/*.mdx"],
332 },
333 experimental: {
334 optimizePackageImports: ["@medusajs/icons", "@medusajs/ui", "elkjs"],
335 webpackMemoryOptimizations: true,
336 },
337 rewrites: async () => {
338 return {
339 beforeFiles: [
340 {
341 source: "/index.html.md",
342 destination: "/md-content",
343 },
344 {
345 source: "/index.md",
346 destination: "/md-content",
347 },
348 {
349 source: "/:path*/index.html.md",
350 destination: "/md-content/:path*",
351 },
352 {
353 source: "/:path*/index.md",
354 destination: "/md-content/:path*",
355 },
356 {
357 source: "/:path*.md",
358 destination: "/md-content/:path*",
359 },
360 {
361 source: "/:first((?!md-content)[^/]+)/:rest*/",
362 has: [
363 {
364 type: "header",
365 key: "Accept",
366 value: ".*(text/markdown|text/plain).*",
367 },
368 ],
369 destination: "/md-content/:first/:rest*",
370 },
371 {
372 source: "/",
373 has: [
374 {
375 type: "header",
376 key: "Accept",
377 value: ".*(text/markdown|text/plain).*",
378 },
379 ],
380 destination: "/md-content",
381 },
382 {
383 source: "/:first((?!md-content)[^/]+)/:rest*",
384 has: [
385 {
386 type: "header",
387 key: "Accept",
388 value: ".*(text/markdown|text/plain).*",
389 },
390 ],
391 destination: "/md-content/:first/:rest*",
392 },
393 ],
394 }
395 },
396 }
397
398 const withBundleAnalyzer = bundleAnalyzer({
399 enabled: process.env.ANALYZE === "true",
400 })
401
402 export default withMDX(withBundleAnalyzer(nextConfig))