Storybook recommends using the @storybook/addon-postcss
for customizing the postCSS config from now on (instead of relying on customizing the postcss-loader
):
-
Add the postCSS addon to your installation
npm i -D @storybook/addon-postcss # or yarn add -D @storybook/addon-postcss
-
Create the
postcss.config.js
in the project root// postcss.config.js module.exports = { plugins: { tailwindcss: {}, autoprefixer: {}, } }
-
Add the plugin to your
.storybook/main.js
// .storybook/main.js module.exports = { ... addons: [ ... { name: '@storybook/addon-postcss', options: { cssLoaderOptions: { // When you have splitted your css over multiple files // and use @import('./other-styles.css') importLoaders: 1, }, postcssLoaderOptions: { // When using postCSS 8 implementation: require('postcss'), }, }, }, ], };
-
Import your css file in the
.storybook/preview.js
// .storybook/preview.js import '../src/styles.css';