Skip to content

Commit

Permalink
Allow using custom loader and options
Browse files Browse the repository at this point in the history
  • Loading branch information
phuctm97 committed Jan 29, 2021
1 parent 5a73859 commit b2b9cd4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/next-mdx/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
module.exports = (pluginOptions = {}) => (nextConfig = {}) => {
const extension = pluginOptions.extension || /\.mdx$/
const loader = pluginOptions.loader || require.resolve('@mdx-js/loader')

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,
},
],
use:
typeof pluginOptions.options === 'function'
? (info) => [
options.defaultLoaders.babel,
{ loader, options: pluginOptions.options(info) },
]
: [
options.defaultLoaders.babel,
{ loader, options: pluginOptions.options },
],
})

if (typeof nextConfig.webpack === 'function') {
Expand Down

0 comments on commit b2b9cd4

Please sign in to comment.