-
Notifications
You must be signed in to change notification settings - Fork 27.5k
/
Copy pathindex.js
68 lines (62 loc) · 2.06 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
59
60
61
62
63
64
65
66
67
68
module.exports =
(pluginOptions = {}) =>
(inputConfig = {}) => {
const extension = pluginOptions.extension || /\.mdx$/
const userProvidedMdxOptions = pluginOptions.options
const mdxRsOptions = inputConfig?.experimental?.mdxRs
const loader = mdxRsOptions
? {
loader: require.resolve('./mdx-rs-loader'),
options: {
providerImportSource: 'next-mdx-import-source-file',
...userProvidedMdxOptions,
// mdxRsOptions is a union of boolean and object type of MdxTransformOptions
...(mdxRsOptions === true ? {} : mdxRsOptions),
},
}
: {
loader: require.resolve('./mdx-js-loader'),
options: {
providerImportSource: 'next-mdx-import-source-file',
...userProvidedMdxOptions,
},
}
let nextConfig = Object.assign({}, inputConfig, {
webpack(config, options) {
config.resolve.alias['next-mdx-import-source-file'] = [
'private-next-root-dir/src/mdx-components',
'private-next-root-dir/mdx-components',
'@mdx-js/react',
]
config.module.rules.push({
test: extension,
use: [options.defaultLoaders.babel, loader],
})
if (typeof inputConfig.webpack === 'function') {
return inputConfig.webpack(config, options)
}
return config
},
})
if (process.env.TURBOPACK) {
nextConfig.experimental = Object.assign({}, nextConfig?.experimental, {
turbo: Object.assign({}, nextConfig?.experimental?.turbo, {
rules: Object.assign({}, nextConfig?.experimental?.turbo?.rules, {
'*.mdx': {
loaders: [loader],
as: '*.tsx',
},
}),
resolveAlias: Object.assign(
{},
nextConfig?.experimental?.turbo?.resolveAlias,
{
'next-mdx-import-source-file':
'@vercel/turbopack-next/mdx-import-source',
}
),
}),
})
}
return nextConfig
}