Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.

Commit 974ea46

Browse files
committed
Update README
1 parent ad6895e commit 974ea46

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

README.md

+39-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,48 @@
11
# require-context.macro
22

3-
A macro needed for some advanced Storybook setups
3+
A macro needed for some advanced Storybook@4 and Storybook@3 setups
44

55
[![Babel Macro](https://img.shields.io/badge/babel--macro-%F0%9F%8E%A3-f5da55.svg?style=flat-square)](https://github.com/kentcdodds/babel-plugin-macros)
66

77
Credit to [the original plugin](https://github.com/smrq/babel-plugin-require-context-hook/).
88

99
## Usage
1010

11-
Ensure you have `babel-plugin-macros` installed within your project. Afterwards, simply import this function and call it in place of `require.context()`.
11+
Ensure you have `babel-plugin-macros` installed within your project.
12+
13+
`yarn add -D babel-plugin-macros`
14+
15+
Then install this specific macro
16+
17+
`yarn add -D require-context.macro`
18+
19+
Afterwards, simply import this function and call it in place of `require.context()` inside
20+
`.storybook/config.js`.
21+
22+
```javascript
23+
// .storybook/config.js
24+
25+
import { configure } from '@storybook/react';
26+
import requireContext from 'require-context.macro';
27+
28+
import '../src/index.css';
29+
30+
const req = requireContext('../src/components', true, /\.stories\.js$/);
31+
32+
function loadStories() {
33+
req.keys().forEach((filename) => req(filename));
34+
}
35+
36+
configure(loadStories, module);
37+
```
38+
39+
You may also need to make Storybook aware of the fact that you're using Babel macros! You can do
40+
this by declaring `macros` as one of the options in your array of plugins within your babel config.
41+
42+
One example, with a `.babelrc` at the root-level of your repository:
43+
44+
```json
45+
{
46+
"plugins": ["macros"]
47+
}
48+
```

0 commit comments

Comments
 (0)