Skip to content

Commit d607151

Browse files
authored
Merge pull request #8 from storybookjs/update-readme
Update README.md [skip ci]
2 parents 5efb936 + 9168f3e commit d607151

File tree

1 file changed

+62
-4
lines changed

1 file changed

+62
-4
lines changed

README.md

+62-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,68 @@
1-
## @storybook/csf-mdx2
1+
## @storybook/mdx2-csf
22

3-
FIXME: Add description of the project
3+
Storybook's `mdx2-csf` is a compiler that turns MDXv2 input into CSF output.
44

5-
## Getting Started
5+
For example, the following input:
66

7-
FIXME: Add getting started steps
7+
```mdx
8+
import { Meta, Story } from '@storybook/addon-docs';
9+
10+
<Meta title="atoms/Button" />
11+
12+
<Story name="Bar">
13+
<Button>hello</Button>
14+
</Story>
15+
```
16+
17+
Might be transformed into the following CSF (over-simplified):
18+
19+
```js
20+
export default {
21+
title: 'atoms/Button',
22+
};
23+
24+
export const Bar = () => <Button>hello</Button>;
25+
```
26+
27+
## API
28+
29+
This library exports an async function to compile MDX, `compile`.
30+
It does not support a synchronous compiler because it uses asynchronous
31+
imports to bridge the ESM/CJS gap. The underlying MDXv2 libraries only
32+
support pure ESM, but this library is used in CJS environments.
33+
34+
### compile
35+
36+
Asynchronously compile a string:
37+
38+
```js
39+
import { compile } from '@storybook/mdx2-csf';
40+
41+
const code = '# hello\n\nworld';
42+
const output = await compile(code);
43+
```
44+
45+
## Loader
46+
47+
In addition, this library supports a simple Webpack loader that mirrors MDXv1's loader, but adds Webpack5 support. It doesn't use MDXv2's loader because it is prohibitively complex, and we want this to be interchangeable with the `@storybook/mdx1-csf`'s loader which is also based on the MDXv1 loader.
48+
49+
```js
50+
module.exports = {
51+
module: {
52+
rules: [
53+
{
54+
test: /\.(stories|story)\.mdx$/,
55+
use: [
56+
{
57+
loader: require.resolve('@storybook/mdx2-csf/loader'),
58+
options: {},
59+
},
60+
],
61+
},
62+
],
63+
},
64+
};
65+
```
866

967
## Contributing
1068

0 commit comments

Comments
 (0)