Integrate Vanilla Extract and Storybook
Get zero-runtime stylesheets in TypeScript. This recipe shows you how to get the most out of Vanilla Extract in Storybook.
If you're already using Vanilla Extract in your project, you may already have these dependencies installed.
First of all, install the required dependencies:
For Vite users, Storybook uses your project's
vite.config.js for its build configuration. This means if your project uses Vanilla Extract, it's also already configured for your Storybook. 🎉
You can view a full example on Stackblitz.
For Webpack users, @storybook/addon-styling-webpack can get your Storybook up and running with Vanilla Extract in a few lines of code.
Run the following script to install and register the addon:
This will run a configuration script that will walk you through setting up the addon. If prompted, select
Vanilla Extract as your CSS processor.
Did the configuration script fail?
Under the hood, this command runs
npx @storybook/auto-config styling, which is responsible for reading your project and attempting to configure your Storybook Webpack for your desired tools. If running that command directly does not resolve your issue, please consider filing a bug report on the @storybook/auto-config repository so that we can further improve it. For manual configuration instructions for Less, you can refer to the documentation.
For an example of manual configuration, you can view a full example on Stackblitz.
Now you're ready to use Vanilla Extract with Storybook. 🎉 If you use Vanilla Extract at work, we'd love your feedback on the Vanilla Extract + Storybook experience.
Join the maintainers and our thriving community in Discord.