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 cloud: {
44 projectPath: path.resolve("..", "cloud"),
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 cloud: {
68 url: process.env.NEXT_PUBLIC_CLOUD_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 || "/user-guide",
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 "../!(user-guide)/.next/**",
135 ],
136 },
137 experimental: {
138 optimizePackageImports: ["@medusajs/icons", "@medusajs/ui"],
139 },
140 rewrites: async () => {
141 return {
142 beforeFiles: [
143 {
144 source: "/index.html.md",
145 destination: "/md-content",
146 },
147 {
148 source: "/index.md",
149 destination: "/md-content",
150 },
151 {
152 source: "/:path*/index.html.md",
153 destination: "/md-content/:path*",
154 },
155 {
156 source: "/:path*/index.md",
157 destination: "/md-content/:path*",
158 },
159 {
160 source: "/:path*.md",
161 destination: "/md-content/:path*",
162 },
163 {
164 source: "/:first((?!md-content)[^/]+)/:rest*/",
165 has: [
166 {
167 type: "header",
168 key: "Accept",
169 value: ".*(text/markdown|text/plain).*",
170 },
171 ],
172 destination: "/md-content/:first/:rest*",
173 },
174 {
175 source: "/",
176 has: [
177 {
178 type: "header",
179 key: "Accept",
180 value: ".*(text/markdown|text/plain).*",
181 },
182 ],
183 destination: "/md-content",
184 },
185 {
186 source: "/:first((?!md-content)[^/]+)/:rest*",
187 has: [
188 {
189 type: "header",
190 key: "Accept",
191 value: ".*(text/markdown|text/plain).*",
192 },
193 ],
194 destination: "/md-content/:first/:rest*",
195 },
196 ],
197 }
198 },
199 }
200
201 const withBundleAnalyzer = bundleAnalyzer({
202 enabled: process.env.ANALYZE === "true",
203 })
204
205 export default withMDX(withBundleAnalyzer(nextConfig))