-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide.config.js
143 lines (141 loc) · 3.92 KB
/
styleguide.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
const path = require('path')
const pkg = require('./package.json')
const { theme, styles } = require('./styleguide.style')
module.exports = {
title: `REACT-BDMAP`,
sections: [
{
name: '快速开始',
content: 'README.md',
},
{
name: '基础',
components: ['src/BDMapLoader.tsx', 'src/BDMap.tsx'],
sectionDepth: 1,
},
{
name: '控件',
components: 'src/controls/[A-Z]*.tsx',
sections: [
{
name: '版权控件 - CopyrightControl',
components: ['src/controls/CopyrightControl/*.tsx'],
},
],
sectionDepth: 1,
},
{
name: '覆盖物',
components: 'src/overlays/[A-Z]*.tsx',
sectionDepth: 1,
},
{
name: '地图图层',
components: [
'src/tileLayers/TileLayer.tsx',
'src/tileLayers/TrafficLayer.tsx',
'src/tileLayers/CustomTileLayer.tsx',
'src/tileLayers/CustomLayer.tsx',
],
sectionDepth: 0,
},
{
name: '其他',
sections: [
{
name: 'withMap',
content: 'docs/withMap.md',
},
{
name: '右键菜单',
components: ['src/ContextMenu/*.tsx'],
},
],
sectionDepth: 1,
},
],
// 每一节一页, 避免加载多个地图实例
pagePerSection: true,
ribbon: {
url: 'https://github.com/carney520/react-bdmap',
text: 'Star me on GitHub',
},
// 配置导出路径
getComponentPathLine(cppath) {
const srcDir = path.resolve('src')
const dirname = path
.dirname(path.relative(srcDir, cppath))
.split(path.sep)
.join('/')
const name = path.basename(cppath, '.tsx')
return `import ${name} from '${path.posix.join(pkg.name, dirname, name)}'`
},
// 配置对应的example 文档
getExampleFilename(cppath) {
const baseDir = path.resolve('docs')
const srcDir = path.resolve('src')
const relative = path.relative(srcDir, cppath)
return path.join(baseDir, relative).replace(/\.tsx?$/, '.md')
},
editorConfig: {
theme: 'monokai',
},
template: {
head: {
links: [
{
rel: 'stylesheet',
href: 'https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.4.1/semantic.min.css',
},
],
},
},
theme: theme,
styles: styles,
exampleMode: 'expand',
usageMode: 'expand',
require: [path.resolve(__dirname, 'docs/helpers/setup.tsx')],
// Typescript支持
resolver: require('react-docgen').resolver.findAllComponentDefinitions,
propsParser: require('react-docgen-typescript').withCustomConfig('./tsconfig.json', []).parse,
styleguideComponents: {
LogoRenderer: path.join(__dirname, 'rsg-components/Logo'),
ReactComponentRenderer: path.join(__dirname, 'rsg-components/ReactComponent'),
},
webpackConfig: {
resolve: {
// Add `.ts` and `.tsx` as a resolvable extension.
extensions: ['.ts', '.tsx', '.js'],
},
module: {
rules: [
{
oneOf: [
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
exclude: /node_modules/,
loader: require.resolve('babel-loader'),
options: {
babelrc: false,
configFile: false,
presets: [require.resolve('babel-preset-react-app')],
cacheDirectory: true,
},
},
{
loader: require.resolve('file-loader'),
// Exclude `js` files to keep "css" loader working as it injects
// its runtime that would otherwise be processed through "file" loader.
// Also exclude `html` and `json` extensions so they get processed
// by webpacks internal loaders.
exclude: [/\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/],
options: {
name: 'static/media/[name].[hash:8].[ext]',
},
},
],
},
],
},
},
}