-
Notifications
You must be signed in to change notification settings - Fork 423
Expand file tree
/
Copy pathnext.config.mjs
More file actions
69 lines (58 loc) · 1.89 KB
/
next.config.mjs
File metadata and controls
69 lines (58 loc) · 1.89 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
import nextra from 'nextra'
import remarkMath from 'remark-math'
import rehypeKatex from 'rehype-katex'
import remarkReplaceVariables from './plugins/remark-replace-variables.mjs'
const stripMdxRouteMetadataLoader = new URL(
'./loaders/strip-mdx-route-metadata.cjs',
import.meta.url,
).pathname
function addMdxRouteMetadataLoader(rule) {
if (!rule || typeof rule !== 'object') return
if (Array.isArray(rule.oneOf)) {
for (const childRule of rule.oneOf) {
addMdxRouteMetadataLoader(childRule)
}
}
if (!Array.isArray(rule.use)) return
const nextraLoaderIndex = rule.use.findIndex((loader) => {
const loaderPath = typeof loader === 'string' ? loader : loader?.loader
return loaderPath?.includes('nextra/loader')
})
if (nextraLoaderIndex === -1) return
rule.use.splice(nextraLoaderIndex, 0, stripMdxRouteMetadataLoader)
}
// Set up Nextra with its configuration
const withNextra = nextra({
defaultShowCopyCode: true,
mdxOptions: {
remarkPlugins: [remarkReplaceVariables, remarkMath],
rehypePlugins: [rehypeKatex],
},
})
// Follow VitePress pattern: use BASE environment variable with trailing slash
const { BASE: base = "" } = process.env;
const basePath = base ? base.replace(/\/$/, '') : undefined; // Remove trailing slash for Next.js
// Export the final Next.js config with Nextra included
export default withNextra({
// Add regular Next.js options here
basePath: basePath,
assetPrefix: base || undefined, // Keep trailing slash for assets
output: 'export',
trailingSlash: true,
images: {
unoptimized: true,
},
experimental: {
// mdxRs is disabled because it doesn't support custom remark plugins
},
webpack: (config) => {
for (const rule of config.module.rules) {
addMdxRouteMetadataLoader(rule)
}
config.watchOptions = {
...config.watchOptions,
ignored: ['**/node_modules/**']
}
return config
}
})