rsnext/packages/next-mdx/index.js
Kristoffer K 104b8d4732
fix(next-mdx): resolve webpack loader (#17983)
**What's the problem this PR addresses?**

`@next/mdx` adds the webpack loader `@mdx-js/loader` without resolving it to an absolute path

Depends on https://github.com/vercel/next.js/pull/17606

**How did you fix it?**

`require.resolve` the webpack loader before adding it
2021-01-04 16:24:16 +00:00

24 lines
599 B
JavaScript

module.exports = (pluginOptions = {}) => (nextConfig = {}) => {
const extension = pluginOptions.extension || /\.mdx$/
return Object.assign({}, nextConfig, {
webpack(config, options) {
config.module.rules.push({
test: extension,
use: [
options.defaultLoaders.babel,
{
loader: require.resolve('@mdx-js/loader'),
options: pluginOptions.options,
},
],
})
if (typeof nextConfig.webpack === 'function') {
return nextConfig.webpack(config, options)
}
return config
},
})
}