What is @storybook/core?
The @storybook/core package is a part of Storybook, which is an open-source tool for developing UI components in isolation for React, Vue, Angular, and many other frameworks. It allows developers to create component libraries, interactive examples, and UI documentation. The core package is responsible for the fundamental functionalities of Storybook, including the server, UI, and the management of stories.
What are @storybook/core's main functionalities?
Custom Storybook Configuration
This code snippet demonstrates how to customize Storybook's configuration, including specifying where to find stories, which addons to use, the framework (e.g., React), and the builder (e.g., Webpack 5).
module.exports = {
stories: ['../src/**/*.stories.js'],
addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
framework: '@storybook/react',
core: {
builder: 'webpack5'
}
};
Adding Decorators
Decorators are a way to wrap stories with extra markup or styling. This code sample shows how to add a decorator globally in `.storybook/preview.js` that adds margin around each story.
export const decorators = [(Story) => <div style={{ margin: '3em' }}><Story/></div>];
Custom Webpack Configuration
This demonstrates how to extend Storybook's default Webpack configuration to support additional file types or loaders, in this case, adding support for SCSS files.
const path = require('path');
module.exports = {
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.scss$/,
use: ['style-loader', 'css-loader', 'sass-loader'],
include: path.resolve(__dirname, '../'),
});
return config;
},
};
Other packages similar to @storybook/core
docz
Docz is a documentation tool that uses MDX to help you write documentation and build component libraries. It's similar to Storybook in that it focuses on components but differs in its approach by leveraging Markdown and providing a more documentation-oriented experience.
Storybook Core
The @storybook/core
package is the core of Storybook. It is responsible for the following:
- the main UI of storybook
- the UI used by addons
- the API used by addons
- the API used by the CLI
- the API used by the server
- prebundled code used by the browser
- static assets used by the browser
- utilities for CSF, MDX & Docs
Private package
This package is not intended to be used by anyone but storybook internally.
Even though this is where all of the code is located, it is NOT to be the entry point when using functionality within!
Consumers of the code should import like so:
import { addons } from 'storybook/internal/manager-api';
Importing from @storybook/core
is explicitly NOT supported; it WILL break in a future version of storybook, very likely in a non-major version bump.
For maintainers
When to use @storybook/core
In the following packages you should import from @storybook/core
(and ONLY from @storybook/core
):
@storybook/core
@storybook/codemod
To prevent cyclical dependencies, these packages cannot depend on the storybook
package.
When to use storybook/internal
In every other package you should import from storybook/internal
(and ONLY from storybook/internal
).
The heuristic is simple:
If you see a peerDependency on storybook
in the package.json
of the package you are working on, you should import from storybook/internal
.
The 1 exception: the storybook
package itself
The sole exception is the storybook
package itself.
Obviously, the storybook
package cannot depend on itself, so it must import from @storybook/core
.
8.4.0
Storybook 8.4 comes with a ton of exciting new features designed to give you the best experience developing, testing, and debugging tests in the browser!
- ▶️ Unified UI for component testing
- 5️⃣ Svelte 5 and Svelte CSF support
- ⚛️ React Native Storybook 8 release
- 🏷️ Tags-based filtering to organize your Storybook
- 🫧 Dependency cleanup to reduce install footprint
- 💯 Hundreds more improvements
<details>
<summary>List of all updates</summary>
- Addon Test: Adjust file exports to be ESM/CJS compatible - #29471, thanks @valentinpalkovic!
- Addon Test: Error when addon interactions exists - #29434, thanks @valentinpalkovic!
- Addon Test: Escape XML when converting ANSI to HTML in test errors - #29446, thanks @ghengeveld!
- Addon Test: Fix hiding stacktrace for assertion errors in test panel - #29458, thanks @ghengeveld!
- Addon Test: Improve Error Handling - #29476, thanks @valentinpalkovic!
- Addon Test: Improve postinstall script - #29479, thanks @yannbf!
- Addon Test: Improve unsupported vitest message - #29486, thanks @valentinpalkovic!
- Addon Test: Only register testing module in Vite projects - #29472, thanks @yannbf!
- Addon Test: Throttle Vitest progress updates more heavily - #29482, thanks @ghengeveld!
- Addon-docs, blocks: Prebundle dependencies - #29301, thanks @JReinhold!
- Addon-Test: Support for
@vitest/browser
v2.1.2 - #29407, thanks @strozw! - Blocks: Prebundle
es-toolkit
- #29259, thanks @JReinhold! - Builder-vite: Replace .at() call with [] in codegen - #29048, thanks @Chudesnov!
- CLI: Don't add
@storybook/addon-links
by default - #29177, thanks @tobiasdiez! - CLI: Ensure
.gitignore
updated via CLI ends with a newline - #29124, thanks @3w36zj6! - CLI: Fix
yarn
detection - #29448, thanks @ndelangen! - CLI: Migrate from
chalk
to picocolors
- #28262, thanks @43081j! - CLI: Refactor NPMProxy error parsing logic - #29459, thanks @yannbf!
- ConfigFile: Fix
export { X }
parsing - #29344, thanks @vctqs1! - Core: Add unified UI Testing Module - #29241, thanks @yannbf!
- Core: Close story status menu when selecting an item - #29455, thanks @ghengeveld!
- Core: Fix building Storybook deleting project root files - #29371, thanks @JReinhold!
- Core: Fix race condition during empty folder init - #29490, thanks @valentinpalkovic!
- Core: Make
prettier
an optional peer dependency - #29223, thanks @JReinhold! - Core: Migrate from
express
to polka
- #29230, thanks @43081j! - Core: Migrate from
qs
to picoquery
- #28315, thanks @43081j! - Core: Open 'Component tests' addon panel when clicking a story status - #29456, thanks @ghengeveld!
- Core: Remove
handlebars
usage - #29208, thanks @ndelangen! - Core: Remove dependence on
file-system-cache
- #29256, thanks @ndelangen! - Core: Replace
fs-extra
with the native APIs - #29126, thanks @ziebam! - Core: Replace
lodash
with es-toolkit
- #28981, thanks @ndelangen! - Core: Show checkmark icon in story status dropdown and update status label for component tests - #29451, thanks @ghengeveld!
- Core: Show tooltip on filter toggles to clarify their purpose - #29447, thanks @ghengeveld!
- Core: Track test provider state in sessionStorage - #29450, thanks @ghengeveld!
- Core: Upgrade
esbuild
, broadening version range - #29254, thanks @ndelangen! - Dependencies: Upgrade VTA to v3.1.0 - #29449, thanks @ghengeveld!
- Dependencies: Upgrade VTA to v3.2.0 to resolve peerDep conflict - #29461, thanks @ghengeveld!
- Interactions: Escape xml of interactions errors - #29414, thanks @kasperpeulen!
- Maintenance: Fix broken and outdated documentation links - #29412, thanks @jonniebigodes!
- Manager: Add tags property to ComponentEntry objects - #29343, thanks @Sidnioulz!
- React: Prebundle all of
renderers/react
's dependencies - #29298, thanks @ndelangen! - Svelte: Improve argTypes inference with
svelte2tsx
- support runes - #29423, thanks @JReinhold! - Test: Remove unused
util
dependency - #29310, thanks @JReinhold! - UI: Brand image css class conflict causes image to resize on hot reloads - #29129, thanks @ShreySinha02!
- UI: Fix RefIndicator to use CheckIcon instead of string - #29209, thanks @JSMike!
- UI: Simple tag filtering - #29333, thanks @shilman!
- UI: Use production-mode
react
in manager - #29197, thanks @ndelangen! - Viewport-addon: Add InitialViewportKeys type to viewport addon - #29182, thanks @hyeongrok7874!
- Vite: Add jsdoc-type-pratt-parser to
optimizeDeps
- #29179, thanks @tobiasdiez! - Vite: Cleanup and prebundle dependencies - #29302, thanks @JReinhold!
- Webpack: Fix export 'act' (imported as 'React4') was not found in 'react' errors in webpack - #29235, thanks @kasperpeulen!
</details>