forked from devaublanc/ifs-test-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyleguide.config.js
141 lines (131 loc) · 5.72 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
const path = require('path')
// postcss
const webpackPostcssTools = require('webpack-postcss-tools')
const autoprefixer = require('autoprefixer')
const postcssCustomProperties = require('postcss-custom-properties')
const postcssRebeccaPurple = require('postcss-color-rebeccapurple')
const postcssSvgInline = require('postcss-inline-svg')
const postcssCalc = require('postcss-calc')
const globalMap = webpackPostcssTools.makeVarMap('src/config/css/global.css');
const variablesMap = Object.assign({}, globalMap.vars);
const PATHS = {
src: path.join(__dirname, 'src'),
lib: path.join(__dirname, 'node_modules')
}
module.exports = {
title: 'React-UI styleguide',
sections: [
{
name: 'Volt UI',
components: 'src/components/*/*.js'
}
],
template: 'styleguide.html',
skipComponentsWithoutExample: true,
highlightTheme: 'base16-light',
getExampleFilename: function(componentpath) {
return componentpath.replace(/\.js?$/, '.md')
},
handlers: require('react-docgen').defaultHandlers.concat(function (documentation, docPath) {
// Calculate a display name for components based upon the declared class name.
if (docPath.value.type === 'ClassDeclaration' && docPath.value.id.type === 'Identifier') {
documentation.set('displayName', docPath.value.id.name);
// Calculate the key required to find the component in the module exports
if (docPath.parentPath.value.type === 'ExportNamedDeclaration') {
documentation.set('path', docPath.value.id.name);
}
}
// The component is the default export
if (docPath.parentPath.value.type === 'ExportDefaultDeclaration') {
documentation.set('docPath', 'default');
}
}),
updateWebpackConfig(webpackConfig) {
// Your source files folder or array of folders, should not include node_modules
webpackConfig.resolve.alias['rsg-components/Wrapper'] = path.join(__dirname, 'src/components/StyleguideWrapper')
webpackConfig.resolve.alias.components = path.join(__dirname, 'src/components')
webpackConfig.resolve.alias.config = path.join(__dirname, 'src/config')
webpackConfig.module.rules = [
{
test: /\.css$/,
enforce: 'pre',
loader: 'postcss-loader',
options: {
postcss: [
autoprefixer,
postcssCustomProperties({
variables: variablesMap
}),
postcssRebeccaPurple,
postcssSvgInline,
postcssCalc()
]
}
},
{
test: /node_modules[\/\\](remark-parse|character-entities-html4|character-reference-invalid|character-entities-legacy|character-entities|hast-util-sanitize)[\/\\].*\.json$/,
include: /node_modules/,
loader: 'json'
},
{
test: /\.css$/,
include:
[ `${__dirname}/node_modules/codemirror`,
`${__dirname}/node_modules/highlight.js` ],
loader: 'style!css'
},
{
test: /\.css$/,
include: `${__dirname}/node_modules/react-styleguidist/src`,
loader: 'style!css?modules&importLoaders=1&localIdentName=ReactStyleguidist-[name]__[local]'
},
// Babel loader will use your project’s .babelrc
{
test: /\.jsx?$/,
include: [
path.join(__dirname, 'src'),
path.join(__dirname, 'scripts'),
path.join(__dirname, 'node_modules/react-styleguidist/src')
],
loader: 'babel-loader'
},
// Other loaders that is needed for your components
{
// Test expects a RegExp! Note the slashes!
test: /\.css$/,
exclude: /node_modules/,
use: [
'style-loader',
{
loader: 'css-loader',
query: {
modules: 1,
importLoaders: 1,
localIndentName: '[name]__[local]___[hash:base64:5]'
}
},
{
loader: 'postcss-loader'
}
]
},
{ test: /\.json?$/, loader: 'json-loader', include: PATHS.src },
{ test: /\.svg$/, loader: 'url?limit=65000&mimetype=image/svg+xml&name=fonts/[name].[ext]', include: PATHS.src },
{ test: /\.woff$/, loader: 'url?limit=65000&mimetype=application/font-woff&name=fonts/[name].[ext]', include: PATHS.src },
{ test: /\.woff2$/, loader: 'url?limit=65000&mimetype=application/font-woff2&name=fonts/[name].[ext]', include: PATHS.src },
{ test: /\.[ot]tf$/, loader: 'url?limit=65000&mimetype=application/octet-stream&name=fonts/[name].[ext]', include: PATHS.src },
{ test: /\.eot$/, loader: 'url?limit=65000&mimetype=application/vnd.ms-fontobject&name=fonts/[name].[ext]', include: PATHS.src }
]
webpackConfig.plugins[2].options.options.context = __dirname
webpackConfig.plugins[2].options.options.postcss = [
autoprefixer,
postcssCustomProperties({
variables: variablesMap
}),
postcssRebeccaPurple,
postcssSvgInline,
postcssCalc()
]
return webpackConfig
}
}