Storybook preset addons are grouped collections of
addons configurations that support specific use cases in Storybook, such as typescript or MDX support.
A preset is a set of hooks that is called by Storybook on initialization and can override configurations for
Each configuration has a similar signature, accepting a base configuration object and options, as in this webpack example:
The babel functions
managerBabel all configure babel in different ways.
All functions take a Babel configuration object as their argument and can modify it or return a new object.
For example, Storybook's Mihtril support uses plugins internally and here's how it configures babel:
babelis applied to the preview config, after it has been initialized by storybook
babelDefaultis applied to the preview config before any user presets have been applied
managerBabelis applied to the manager.
The webpack functions
managerWebpack configure webpack.
All functions take a webpack4 configuration object.
For example, here is how Storybook automatically adopts
create-react-app's configuration if it's installed, where
applyCRAWebpackConfig is a set of smart heuristics for modifying the input config.
webpackis applied to the preview config after it has been initialized by storybook
webpackFinalis applied to the preview config after all user presets have been applied
managerWebpackis applied to the manager config
The addon config
managerEntries allows you to add addons to Storybook from within a preset. For addons that require custom webpack/babel configuration, it is easier to install the preset, and it will take care of everything.
For example, the Storysource preset contains the following code:
The addon config
config allows you to add extra preview configuration from within a preset, for example to add parameters or decorators from an addon.
For example, the Backgrounds preset contains the following code:
Which in turn invokes:
This is equivalent to exporting the
backgrounds parameter manually in
For users, the name
managerEntries might be a bit too technical, so instead both users and preset-authors can simply use the property:
The array of values can support both references to other presets and addons that should be included into the manager.
Storybook will automatically detect whether a reference to an addon is a preset or a manager entry by checking if the package contains a
./register.js (manager entry), falling back to preset if it is unsure.
If this heuristic is incorrect for an addon you are using, you can explicitly opt in to an entry being an a manager entry using the
Here's what it looks when combining presets and managerEntries in the addons property:
Entries are the place to register entry points for the preview. For example it could be used to make a basic configure-storybook preset that loads all the
*.stories.js files into SB, instead of forcing people to copy-paste the same thing everywhere.
The presets API is also more powerful than the standard configuration options available in Storybook, so it's also possible to use presets for more advanced configuration without actually publishing a preset yourself.
For example, some users want to configure the webpack for Storybook's UI and addons (issue), but this is not possible using standard webpack configuration (it used to be possible before SB4.1). However, you can achieve this with a private preset.
If it doesn't exist yet, create a file
main.js file to:
and extract the configuration to a new file
my-preset.js file wherever you want, if you want to share it far and wide you'll want to make it its own package.