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