2021-08-17 09:18:08 +02:00
|
|
|
module.exports =
|
|
|
|
(pluginOptions = {}) =>
|
|
|
|
(nextConfig = {}) => {
|
|
|
|
const extension = pluginOptions.extension || /\.mdx$/
|
2019-03-04 18:02:45 +01:00
|
|
|
|
2024-04-22 23:51:47 +02:00
|
|
|
const mdxRsOptions = nextConfig?.experimental?.mdxRs
|
|
|
|
const loader = mdxRsOptions
|
2022-11-03 02:24:05 +01:00
|
|
|
? {
|
|
|
|
loader: require.resolve('./mdx-rs-loader'),
|
|
|
|
options: {
|
2023-01-06 22:09:05 +01:00
|
|
|
providerImportSource: 'next-mdx-import-source-file',
|
2022-11-03 02:24:05 +01:00
|
|
|
...pluginOptions.options,
|
2024-04-22 23:51:47 +02:00
|
|
|
// mdxRsOptions is a union of boolean and object type of MdxTransformOptions
|
|
|
|
...(mdxRsOptions === true ? {} : mdxRsOptions),
|
2022-11-03 02:24:05 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
: {
|
|
|
|
loader: require.resolve('@mdx-js/loader'),
|
|
|
|
options: {
|
2023-01-06 22:09:05 +01:00
|
|
|
providerImportSource: 'next-mdx-import-source-file',
|
2022-11-03 02:24:05 +01:00
|
|
|
...pluginOptions.options,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
return Object.assign({}, nextConfig, {
|
|
|
|
webpack(config, options) {
|
2023-01-06 22:09:05 +01:00
|
|
|
config.resolve.alias['next-mdx-import-source-file'] = [
|
2023-03-05 01:46:27 +01:00
|
|
|
'private-next-root-dir/src/mdx-components',
|
2023-01-06 22:09:05 +01:00
|
|
|
'private-next-root-dir/mdx-components',
|
|
|
|
'@mdx-js/react',
|
|
|
|
]
|
2021-08-17 09:18:08 +02:00
|
|
|
config.module.rules.push({
|
|
|
|
test: extension,
|
2023-11-28 10:50:14 +01:00
|
|
|
use: [options.defaultLoaders.babel, loader],
|
2021-08-17 09:18:08 +02:00
|
|
|
})
|
2019-03-04 18:02:45 +01:00
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
if (typeof nextConfig.webpack === 'function') {
|
|
|
|
return nextConfig.webpack(config, options)
|
|
|
|
}
|
2019-03-04 18:02:45 +01:00
|
|
|
|
2021-08-17 09:18:08 +02:00
|
|
|
return config
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|