The component2block Storybook preset auto-injects all generated and authored style files into Storybook. No manual imports needed in preview.ts.
Add the preset to your .storybook/main.ts addons:
// .storybook/main.ts
export default {
addons: [
'@storybook/addon-docs',
'@troychaplin/component2block/preset',
],
};The preset reads c2b.config.json, derives file paths from output.srcDir, and injects any that exist:
| File | Description |
|---|---|
tokens.css |
CSS custom properties (generated) |
fonts.css |
@font-face declarations (generated, if fontFace defined) |
reset.scss |
Structural CSS reset (authored by you) |
content.scss |
Base typography — imports base-styles.scss + your behavioral rules (authored by you) |
All paths are derived from the output.srcDir config value. If output.srcDir is src/styles, the preset looks for src/styles/tokens.css, src/styles/fonts.css, src/styles/reset.scss, and src/styles/content.scss in that directory.
The preset uses Storybook's previewAnnotations API to return file paths for auto-import. Each file path becomes an import in the Storybook preview iframe, making the styles available to all stories.
Files that don't exist on disk are silently skipped. For example, if you haven't defined any fontFace entries, fonts.css won't exist and the preset won't try to inject it.
- Start Storybook:
npm run dev - Open browser dev tools on any story
- Check that
tokens.cssvariables are available on:root - Check that base typography from
base-styles.scssis applied to body and heading elements - Check that
@font-facedeclarations fromfonts.cssare present (if you have font tokens)
With the preset configured, you do not need to import style files in .storybook/preview.ts. The preset handles all style injection automatically.
If you previously had manual imports like these in preview.ts, they can be removed:
// These are no longer needed — the preset handles them
// import '../src/styles/tokens.css';
// import '../src/styles/fonts.css';
// import '../src/styles/reset.scss';
// import '../src/styles/content.scss';