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