rsnext/packages/next-mdx/index.js
OJ Kwon 372f00eb07
fext(next): extend next.config for mdxRs support options (#64801)
### What

Closes PACK-2978, requires https://github.com/vercel/turbo/pull/8005.

PR extends existing mdxRs config from accepting object as well in
addition to current boolean flag, mainly to allow to specify what kind
of markdown types will be used between gfm and commonmark.
2024-04-22 21:51:47 +00:00

44 lines
1.3 KiB
JavaScript

module.exports =
(pluginOptions = {}) =>
(nextConfig = {}) => {
const extension = pluginOptions.extension || /\.mdx$/
const mdxRsOptions = nextConfig?.experimental?.mdxRs
const loader = mdxRsOptions
? {
loader: require.resolve('./mdx-rs-loader'),
options: {
providerImportSource: 'next-mdx-import-source-file',
...pluginOptions.options,
// 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',
...pluginOptions.options,
},
}
return Object.assign({}, nextConfig, {
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 nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
},
})
}