Configuration
By default, Styleguidist will look for styleguide.config.js
file in your project’s root folder. You can change the location of the config file using --config
CLI option.
assetsDir
Type: String
or Array
, optional
Your application static assets folder will be accessible as /
in the style guide dev server.
compilerConfig
Type: Object
, default:
Styleguidist uses Bublé to run ES6 code on the frontend. This config object will be added as the second argument for buble.transform
.
components
Type: String
, Function
or Array
, default: src/components/**/*.{js,jsx,ts,tsx}
- when
String
: a glob pattern that matches all your component modules. - when
Function
: a function that returns an array of module paths. - when
Array
: an array of module paths.
All paths are relative to config folder.
See examples in the Components section.
context
Type: Object
, optional
Modules that will be available for examples. You can use it for utility functions like Lodash or for data fixtures.
Then you can use them in any example:
contextDependencies
Type: String[]
, optional
Array of absolute paths that allow you to specify absolute paths of directories to watch for additions or removals of components.
By default Styleguidist uses common parent directory of your components.
configureServer
Type: Function
, optional
Function that allows you to add endpoints to the underlying Express server:
Your components will be able to invoke the URL http://localhost:6060/custom-endpoint
from their examples.
dangerouslyUpdateWebpackConfig
Type: Function
, optional
danger
You may break Styleguidist by using this option, try to use webpackConfig option instead.
Allows you to modify webpack config without any restrictions.
defaultExample
Type: Boolean
or String
, default: false
For components that do not have an example, a default one can be used. When set to true
, the DefaultExample.md is used, or you can provide the path to your own example Markdown file.
When writing your own default example file, __COMPONENT__
will be replaced by the actual component name at compile time.
exampleMode
Type: String
, default: collapse
Defines the initial state of the example code tab:
collapse
: collapses the tab by default.hide
: hide the tab and it can´t be toggled in the UI.expand
: expand the tab by default.
getComponentPathLine
Type: Function
, default: component filename
Function that returns a component path line (displayed under the component name).
For example, instead of components/Button/Button.js
you can print import Button from 'components/Button';
:
getExampleFilename
Type: Function
, default: finds Readme.md
or ComponentName.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
:
handlers
Type: Function
, optional, default: [react-docgen-displayname-handler]
Function that returns functions used to process the discovered components and generate documentation objects. Default behaviors include discovering component documentation blocks, prop types, and defaults. If setting this property, it is best to build from the default react-docgen handler list, such as in the example below. See the react-docgen handler documentation for more information about handlers.
note
react-docgen-displayname-handler
should be included.
ignore
Type: String[]
, default: ['**/__tests__/**', '**/*.test.{js,jsx,ts,tsx}', '**/*.spec.{js,jsx,ts,tsx}', '**/*.d.ts']
Array of glob pattern that should not be included in the style guide.
caution
You should pass glob patterns, for example, use **/components/Button.js
instead of components/Button.js
.
logger
Type: Object
, by default will use console.*
in CLI or nothing in Node.js API
Custom logger functions:
minimize
Type: Boolean
, default: true
If false
, the production build will not be minimized.
moduleAliases
Type: object
, optional
Define aliases for modules, that you can import in your examples, to make example code more realistic and copypastable:
Check out the webpack resolve.alias documentation for available syntax.
mountPointId
Type: string
, default: rsg-root
The ID of a DOM element where Styleguidist mounts.
pagePerSection
Type: Boolean
, default: false
Render one section or component per page.
If true
, each section will be a single page.
The value may depend on a current environment:
To isolate section’s children as single pages (subroutes), add sectionDepth
into each section with the number of subroutes (depth) to render as single pages.
For example:
printBuildInstructions
Type: Function
, optional
Function that allows you to override the printing of build messages to console.log.
printServerInstructions
Type: Function
, optional
Function that allows you to override the printing of local dev server messages to console.log.
previewDelay
Type: Number
, default: 500
Debounce time in milliseconds used before rendering the changes from the editor. While typing code the preview will not be updated.
propsParser
Type: Function
, optional
Function that allows you to override the mechanism used to parse props from a source file. The default mechanism is using react-docgen to parse props.
require
Type: String[]
, optional
Modules that are required for your style guide. Useful for third-party styles or polyfills.
note
This will add a separate webpack entry for each array item.
Don’t forget to add webpack loaders for each file you add here. For example, to require a CSS file you’ll need:
See Configuring webpack for mode details.
resolver
Type: Function
, optional
Function that allows you to override the mechanism used to identify classes/components to analyze. Default behavior is to find all exported components in each file. You can configure it to find all components or use a custom detection method. See the react-docgen resolver documentation for more information about resolvers.
ribbon
Type: Object
, optional
Show “Fork Me” ribbon in the top right corner.
Use the theme config option to change ribbon style.
sections
Type: Array
, optional
Allows components to be grouped into sections with a title and overview content. Sections can also be content only, with no associated components (for example, a textual introduction). Sections can be nested.
See examples of sections configuration.
serverHost
Type: String
, default: 0.0.0.0
Dev server hostname.
serverPort
Type: Number
, default: process.env.NODE_PORT
or 6060
Dev server port. Can also be set via command line --port=6060
.
showSidebar
Type: Boolean
, default: true
Toggle sidebar visibility. The sidebar will be hidden when opening components or examples in isolation mode even if this value is set to true
. When set to false
, the sidebar will always be hidden.
skipComponentsWithoutExample
Type: Boolean
, default: false
Ignore components that don’t have an example file (as determined by getExampleFilename). These components won’t be accessible from other examples unless you manually require
them.
sortProps
Type: Function
, optional
Function that sorts component props. By default props are sorted such that required props come first, optional props come second. Props in both groups are sorted by their property names.
To disable sorting, use the identity function:
styleguideComponents
Type: Object
, optional
Override React components used to render the style guide:
See an example of customized style guide.
To wrap, rather than replace a component, make sure to import the default implementation using the full path to react-styleguidist
. See an example of wrapping a Styleguidist component.
Note: these components are not guaranteed to be safe from breaking changes in React Styleguidist updates.
styleguideDir
Type: String
, default: styleguide
Folder for static HTML style guide generated with styleguidist build
command.
styles
Type: Object
, String
or Function
, optional
Customize styles of any Styleguidist’s component using an object, a function returning said object or a file path to a file exporting said styles.
See examples in the cookbook.
tip
Using a function allows access to theme variables like in the example below. See available theme variables. The returned object folows the same format as when configured as a litteral.
Note: If using a file path, it has to be absolute or relative to the config file.
template
Type: Object
or Function
, optional.
Change HTML for the style guide app.
An object with options to add a favicon, meta tags, inline JavaScript or CSS, etc. See @vxna/mini-html-webpack-template docs.
A function that returns an HTML string, see mini-html-webpack-plugin docs.
theme
Type: Object
or String
, optional
Customize style guide UI fonts, colors, etc. using a theme object or the path to a file exporting such object.
The path is relative to the config file or absolute.
See examples in the cookbook.
info
See available theme variables.
info
Styles use JSS with these plugins: jss-plugin-isolate, jss-plugin-nested, jss-plugin-camel-case, jss-plugin-default-unit, jss-plugin-compose and jss-plugin-global.
tip
Use React Developer Tools to find component and style names. For example a component <LogoRenderer><h1 className="rsg--logo-53">
corresponds to an example above.
title
Type: String
, default: <app name from package.json> Style Guide
Style guide title.
tocMode
Type: String
default: expand
Defines if the table of contents sections will behave like an accordion:
collapse
: All sections are collapsed by defaultexpand
: Sections cannot be collapsed in the Table Of Contents
Collapse the sections created in the sidebar to reduce the height of the sidebar. This can be useful in large codebases with lots of components to avoid having to scroll too far.
updateDocs
Type: Function
, optional
Function that modifies props, methods, and metadata after parsing a source file. For example, load a component version from a JSON file:
With this component JSDoc comment block:
updateExample
Type: Function
, optional
Function that modifies code example (Markdown fenced code block). For example, you can use it to load examples from files:
Use it like this in your Markdown files:
You can also use this function to dynamically update some of your fenced code blocks that you do not want to be interpreted as React components by using the static modifier.
usageMode
Type: String
, default: collapse
Defines the initial state of the props and methods tab:
collapse
: collapses the tab by default.hide
: hide the tab and it can´t be toggled in the UI.expand
: expand the tab by default.
verbose
Type: Boolean
, default: false
Print debug information. Same as --verbose
command line switch.
version
Type: String
, optional
Style guide version, displayed under the title in the sidebar.
webpackConfig
Type: Object
or Function
, optional
Custom webpack config options: loaders, extensions, plugins, etc. required for your project.
Can be an object:
Or a function:
caution
This option disables config load from webpack.config.js
, load your config manually.
danger
entry
, externals
, output
, watch
, and stats
options will be ignored. For production builds, devtool
will also be ignored.
danger
CommonsChunkPlugins
, HtmlWebpackPlugin
, MiniHtmlWebpackPlugin
, UglifyJsPlugin
, TerserPlugin
, HotModuleReplacementPlugin
plugins will be ignored because Styleguidist already includes them or they may break Styleguidist.
tip
Run style guide in verbose mode to see the actual webpack config used by Styleguidist: npx styleguidist server --verbose
.
See Configuring webpack for examples.