我想使用“react-styleguidist”记录一个ButtonGroup
渲染组件的组件。Button
我有一个 styleguidist webpack 配置,如下所示:
module.exports = {
module: {
rules: [
{
test: /\.jsx?$/,
use: [
{
loader: 'babel-loader'
}
],
exclude: /node_modules/
}
]
},
devtool: 'cheap-module-eval-source-map'
}
我知道我不需要定义常用的加载器和插件,因为 styleguidist 已经在内部添加了它们
在 内部src/components/
,允许styleguidist
获取我的组件的目录结构看起来有点像这样:
Button
index.js
Readme.md
ButtonGroup
index.js
example.js (created for Case II after Case I failed)
Readme.md
案例一
在我Readme.md
的ButtonGroup
目录中:
```jsx
const Button = require('../index')
<ButtonGroup>
<Button type='primary' size='lg'>Hello, World</Button>
<Button type='primary' size='lg'>Hello, Doctor</Button>
</ButtonGroup>
```
当我这样做时,我styleguide
有一个错误说:
SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag (5:2)
案例二
如上图所示,我已尝试将信息包含在example.js
内部目录中,该文件包含:ButtonGroup
import React from 'react'
const ButtonGroup = require('./index')
const Button = require('../index')
export default function ButtonGroupExample (props) {
return (
<ButtonGroup>
<Button>Hello, World</Button>
<Button>Hello, Doctor</Button>
</ButtonGroup>
)
}
现在示例组件被导入到Readme.md
:
```jsx
const Example = require('./example')
(<Example />)
```
引发错误:
TypeError: require(...) is not a function