Back to integrations
@vanilla-extract/css

Integrate Vanilla Extract with Storybook

Get zero-runtime stylesheets in TypeScript.
Prerequisites

This recipe assumes that you already have an app using Vanilla-extract and have just set up Storybook >= 7.0 using the getting started guide. Don't have this? Follow Vanilla-extract's setup instructions then run:

# Add Storybook:
npx storybook@latest init

Configure your Storybook builder

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
yarn add -D @vanilla-extract/vite-plugin
 
# For Webpack users
yarn add -D @vanilla-extract/webpack-plugin mini-css-extract-plugin

Vite

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.

Webpack

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:

npx storybook@latest add @storybook/addon-styling-webpack

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.

Manually configure Webpack

For an example of manual configuration, you can view a full example on Stackblitz.

Get involved

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.

Tags
Contributors
  • ShaunEvening