@mdx-js/loader
Loader for MDX
Last updated 5 years ago by johno .
MIT · Repository · Bugs · Original npm
$ cnpm install @mdx-js/loader 
SYNC missed versions from official npm registry.

@mdx-js/loader

Build Status lerna Join the community on Spectrum

Webpack loader for MDX.

Installation

npm:

npm i -D @mdx-js/loader

Usage

// ...
module: {
  rules: [
    // ...
    {
      test: /\.mdx?$/,
      use: ['babel-loader', '@mdx-js/loader']
    }
  ]
}

The renderer option specifies a string that will be prepended to the generated source allowing for the use of any createElement implementation. By default, that string is:

import React from 'react'
import {mdx} from '@mdx-js/react'

Using the renderer option, one can swap out React for another implementation. The example below wraps a generic JSX compatible function named h.

const renderer = `
import { h } from 'generic-implementation'

const mdx = (function (createElement) {
  return function (name, props, ...children) {
    if (typeof name === 'string') {
      if (name === 'wrapper') return children.map(createElement)
      if (name === 'inlineCode') return createElement('code', props, ...children)
    }

    return createElement(name, props, ...children)
  }
}(h))
`

// ...
module: {
  rules: [
    // ...
    {
      test: /\.mdx?$/,
      use: [
        'babel-loader',
        {
          loader: '@mdx-js/loader'
          options: {
            renderer,
          }
        }
      ]
    }
  ]
}

For more information on why this is required, see this post.

Contribute

See the Support and Contributing guidelines on the MDX website for ways to (get) help.

This project has a Code of Conduct. By interacting with this repository, organisation, or community you agree to abide by its terms.

License

MIT © Compositor and Vercel

Current Tags

  • 2.0.0-ci.53                                ...           ci (4 years ago)
  • 2.1.2                                ...           latest (3 years ago)
  • 2.0.0-rc.2                                ...           next (4 years ago)

16 Versions

  • 2.1.2                                ...           3 years ago
  • 2.0.0                                ...           4 years ago
  • 2.0.0-rc.2                                ...           4 years ago
  • 2.0.0-next.9                                ...           4 years ago
  • 2.0.0-ci.53                                ...           4 years ago
  • 1.6.22                                ...           5 years ago
  • 2.0.0-next.7                                ...           5 years ago
  • 1.6.16-ci.0                                ...           5 years ago
  • 1.6.16                                ...           5 years ago
  • 0.16.8                                ...           7 years ago
  • 0.9.0                                ...           7 years ago
  • 0.15.7                                ...           7 years ago
  • 2.0.0-next.1                                ...           5 years ago
  • 1.6.2-ci.1                                ...           5 years ago
  • 1.6.5                                ...           5 years ago
  • 1.0.20                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org