Join live session: Test your components in browser with Storybook Test
Back to integrations
less

Integrate Less with Storybook

Less is a popular CSS preprocessor that helps you write smaller, reusable styles.
Prerequisites

This recipe assumes that you have an app using Less and have just set up Storybook >=7.0 using the getting started guide. Donโ€™t have this? Then run:

# Add Storybook:
npx storybook@latest init

1. Configure your Storybook builder

Before you begin

If you are using Vite as your Storybook builder, you can skip to the next step.

Firstly, install the @storybook/addon-styling-webpack addon.

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. When prompted, select Less from the configuration options.

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 here.

2. Import global styles

If you have any global styles you would like to expose for your stories, you can now import them into your preview.js file:

// .storybook/preview.js
 
import '../src/index.less';

Get involved

Now you're ready to use Less with Storybook. ๐ŸŽ‰ If you use Less at work, we'd love your feedback on the Less + Storybook experience.

Join the maintainers and our thriving community in Discord.

Tags
Contributors
  • ShaunEvening
    ShaunEvening