Skip to content

Commit

Permalink
docs update / use renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
axdg committed Aug 11, 2019
1 parent f65c2a8 commit 262bc10
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
12 changes: 5 additions & 7 deletions packages/loader/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
const {getOptions} = require('loader-utils')
const mdx = require('@mdx-js/mdx')

const DEFAULT_PREPEND = `
import React from 'react'
import { mdx } from '@mdx-js/react'
const DEFAULT_RENDERER = `
import React from 'react'
import { mdx } from '@mdx-js/react'
`
.split('\n')
.map(l => l.trim())

const loader = async function(content) {
const callback = this.async()
Expand All @@ -22,9 +20,9 @@ const loader = async function(content) {
return callback(err)
}

const {prepend = DEFAULT_PREPEND} = options
const {renderer = DEFAULT_RENDERER} = options

const code = `${prepend}\n${result}`
const code = `${renderer}\n${result}`
return callback(null, code)
}

Expand Down
10 changes: 5 additions & 5 deletions packages/loader/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ module: {
}
```

The `prepend` 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:
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:

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

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

```js
const prepend = `
const renderer = `
import { h } from 'generic-implementation'
const mdx = (function (createElement) {
Expand All @@ -68,7 +68,7 @@ module: {
{
loader: '@mdx-js/loader'
options: {
prepend,
renderer,
}
}
]
Expand Down Expand Up @@ -120,4 +120,4 @@ abide by its terms.

[mdx]: https://github.com/mdx-js/mdx

[npm]: https://docs.npmjs.com/cli/install
[npm]: https://docs.npmjs.com/cli/install

0 comments on commit 262bc10

Please sign in to comment.