-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnext.config.ts
More file actions
80 lines (72 loc) · 2.63 KB
/
next.config.ts
File metadata and controls
80 lines (72 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { createMDX } from "fumadocs-mdx/next"
import { NextConfig } from "next"
import path from 'path';
const redirectsMapPath = path.resolve(process.cwd(), 'redirects-map');
const { folderRedirectsMap, fileRedirectsMap, externalRedirectsMap } = require(redirectsMapPath);
const withMDX = createMDX()
const config: NextConfig = {
// Aliases out the eval-based HideIfEmpty to our stub
// as eval() is not allowed on cloudflare workers, so we need to replace it
webpack(config) {
config.resolve.alias = {
...(config.resolve.alias || {}),
// Handle both module path and relative imports from fumadocs-ui
'fumadocs-ui/components/ui/hide-if-empty':
path.resolve(__dirname, 'src/components/HideIfEmptyStub.tsx'),
// Handle the specific fumadocs-ui hide-if-empty component file
[path.resolve(__dirname, 'node_modules/fumadocs-ui/dist/components/ui/hide-if-empty.js')]:
path.resolve(__dirname, 'src/components/HideIfEmptyStub.tsx'),
};
return config;
},
pageExtensions: ["js", "jsx", "ts", "tsx", "md", "mdx"],
basePath: '/docs',
assetPrefix: '/docs',
async rewrites() {
return [
{
source: '/:path*.md',
destination: '/api/raw/:path*',
},
];
},
async redirects() {
const redirects = [
// one-offs that aren't covered by the bulk map
// note: "/docs/" prefix is auto-added to these strings via "basePath" ^
{ source: '/docs/:path*', destination: '/:path*', permanent: true },
{ source: '/installation-via-rn-expo', destination: '/installation-via-expo', permanent: true },
// Redirect /index paths to parent directory
{ source: '/:path*/index', destination: '/:path*', permanent: true },
]
// auto-generate root-to-folder redirects
Object.entries(folderRedirectsMap as Record<string, readonly string[]>).forEach(([folder, slugs]) => {
slugs.forEach((slug) => {
redirects.push({
source: `/${slug}`,
destination: `/${folder}/${slug}`,
permanent: true,
})
})
})
// auto-generate file redirects
Object.entries(fileRedirectsMap as Record<string, string>).forEach(([before, after]) => {
redirects.push({
source: `/${before}`,
destination: `/${after}`,
permanent: true,
})
})
// external redirects
Object.entries(externalRedirectsMap as Record<string, string>).forEach(([source, destination]) => {
redirects.push({
source: `/${source}`,
destination: destination,
permanent: true,
})
})
return redirects;
},
reactStrictMode: true,
}
export default withMDX(config)