Fork of React Style Guide generator react-styleguidist with integration to SourceJS platform.
Original styleguidist example. (example with SourceJS will be available later)
To add automatically generated React props docs use sourcejs-react-docgen plugin. Check SourceJS React bundle example for more insights.
cd sourcejs-project
npm install sourcejs-react-styleguidist --save
Add custom markdown renderer conf into SourceJS options.js
file:
module.exports = { core: { processMd: { languageRenderers: { jsx: require('sourcejs-react-styleguidist/core/lang-jsx').processExample } } } };
After re-running your SourceJS app, plugin will be loaded automatically.
Configure path to components in SourceJS options.js
file:
module.exports = { plugins: { reactStyleguidist: { rootDir: './relative/path/to/components', components: './**/*.jsx' } } };
See Configuration section below for the list of available options.
Examples are written in Markdown where any code blocks will be rendered as a react components. By default any readme.md
in the component folder is treated as an examples file but you can change it with the getExampleFilename
option.
React component example:
```jsx
<Button size="large">Push Me</Button>
```
Any [Markdown](http://daringfireball.net/projects/markdown/):
* Foo;
* bar;
* baz.
SourceJS plugins are loaded together with main application, adding additional initialization steps or changing rendering flow using middleware integration. With this plugin, in development mode, SourceJS in enhanced with webpack middleware, that builds all the React examples on demand and listens to file changes for hot-reloading.
In production mode webpack is not triggered, expecting that bundle is already built (read configuration section for more).
Rendering flow with this plugins looks like this:
webpack-dev-middleware
and webpack-hot-middleware
are loaded from core/index.js
bundle.js
which packs all the components and development tools into one packagereadme.md
files, and saves defined code examplesbundle.js
is loaded onto every page, loading only examples of defined speccode/middleware/index.js
) during rendering flow replaces code examples from readme.md
with special hooks, that are then used as roots to React componentsUse SourceJS options.js
for deep plugin configuration.
enabled
Type: Boolean
Set to false
, if wan't to disable plugin load with SourceJS app.
preBuild
Type: Boolean
Set to true
, if you wan't to automatically build webpack bundle in production mode right after app starts.
rootDir
Type: String
, required Your components sources root folder (eg. ./lib
). Should not point to a folder with the node_modules
folder.
components
Type: String
or Function
, required
String
: a glob pattern that matches all your component modules. Relative to the rootDir
.Function
: function that returns an array of modules.If your components look like components/Button.jsx
or components/Button/Button.jsx
or components/Button/index.jsx
:
components: './components/**/*.jsx'
If your components look like components/Button/Button.js
+ components/Button/index.js
:
components: function(config, glob) { return glob.sync(config.rootDir + '/components/**/*.js').filter(function(module) { return /\/[A-Z][a-z]*\.js$/.test(module); }); },
highlightTheme
Type: String
, default: base16-light
CodeMirror theme name to use for syntax highlighting in examples.
getExampleFilename
Type: Function
, default: finds readme.md
in the component folder Function that returns examples file path for a given component path.
For example, instead of readme.md
you can use ComponentName.examples.md
:
getExampleFilename: function(componentpath) { return componentpath.replace(/\.jsx?$/, '.examples.md'); }
updateWebpackConfig
Type: Function
, optional Function that allows you to modify Webpack config for style guide:
updateWebpackConfig: function(webpackConfig, env) { if (env === 'development') { /* ... modify config ... */ } return webpackConfig; }
Running app with NODE_ENV=production
, initial webpack build won't be triggered. To properly prepare production environment, first run react-styleguidist build command, and only after that run application:
NODE_ENV=production node ./node_modules/sourcejs-react-styleguidist/core/build.js
NODE_ENV=production npm start
Note: this command should be ran from SourceJS root folder, where node_modules
is placed.
Alternatively, you can set preBuild
to true in plugin configuration, to build webpack bundle once app is ran in production mode. This will require less build steps, but may cause higher load in production environment container.
Everyone is welcome to contribute. Please take a moment to review the contributing guidelines.
The MIT License, see the included license.md file.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4