/
index.js
58 lines (49 loc) · 1.54 KB
/
index.js
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
import { NextraPlugin, pageMapCache } from './plugin'
import { MARKDOWN_EXTENSION_REGEX } from './constants'
const defaultExtensions = ['js', 'jsx', 'ts', 'tsx']
const markdownExtensions = ['md', 'mdx']
module.exports =
(...args) =>
(nextConfig = {}) => {
const nextraConfig =
typeof args[0] === 'string'
? {
theme: args[0],
themeConfig: args[1]
}
: args[0]
const locales = nextConfig.i18n?.locales || null
const defaultLocale = nextConfig.i18n?.defaultLocale || null
let pageExtensions = nextConfig.pageExtensions || [...defaultExtensions]
pageExtensions = pageExtensions.concat(markdownExtensions)
if (locales) {
console.log(
'[nextra] You have Next.js i18n enabled, read here (TODO: link) for the docs.'
)
}
return Object.assign({}, nextConfig, {
pageExtensions,
webpack(config, options) {
const nextra = new NextraPlugin(nextraConfig)
if (!config.plugins) {
config.plugins = [nextra]
} else {
config.plugins.push(nextra)
}
config.module.rules.push({
test: MARKDOWN_EXTENSION_REGEX,
use: [
options.defaultLoaders.babel,
{
loader: 'nextra/loader',
options: { ...nextraConfig, locales, defaultLocale, pageMapCache }
}
]
})
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
}
})
}