UNPKG

1.17 kBMarkdownView Raw
1# `babel-plugin-apply-mdx-type-prop`
2
3Babel plugin that applies the `mdxType` prop which is
4used by the [MDX](https://mdxjs.com) pragma.
5
6It also stores all components encountered as `names` in
7the plugin state.
8
9## Installation
10
11```sh
12yarn add babel-plugin-apply-mdx-type-prop
13```
14
15## Usage
16
17```js
18const babel = require('@babel/core')
19
20const BabelPluginApplyMdxTypeProp = require('babel-plugin-apply-mdx-type-prop')
21
22const jsx = `
23export const Foo = () => (
24 <div>
25 <Button />
26 </div>
27)
28
29export default () => (
30 <>
31 <h1>Hello!</h1>
32 <TomatoBox />
33 </>
34)
35`
36
37const plugin = new BabelPluginApplyMdxTypeProp()
38
39const result = babel.transform(jsx, {
40 configFile: false,
41 plugins: ['@babel/plugin-syntax-jsx', plugin.plugin]
42})
43
44console.log(result.code)
45console.log(plugin.state.names)
46```
47
48### Input
49
50```js
51export const Foo = () => (
52 <div>
53 <Button />
54 </div>
55)
56
57export default () => (
58 <>
59 <h1>Hello!</h1>
60 <TomatoBox />
61 </>
62)
63```
64
65### Output
66
67```js
68export const Foo = () => (
69 <div>
70 <Button mdxType="Button" />
71 </div>
72)
73
74export default () => (
75 <>
76 <h1>Hello!</h1>
77 <TomatoBox mdxType="Button" />
78 </>
79)
80```
81
82## License
83
84MIT