Tailwind - Storybook - react - typescript. How to add tailwind to storybook #13538
-
How to add tailwind to storybookI created my project using Then I installed Then i added storybook by running command Everything till now works fine. But now I need to add I tried to import For clarity here are some of my config files.
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hey @nivekithan I believe I answered you on Stackoveflow but I'll put the answer here so it can help others as well! You're almost there. The missing piece of your config is to add a webpack configuration to apply tailwind to postcss-loader: // .storybook/main.js
const path = require('path')
module.exports = {
stories: [
'../src/**/*.stories.mdx',
'../src/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/preset-create-react-app',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.css$/,
use: [
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
],
include: path.resolve(__dirname, '../'),
})
return config
},
} |
Beta Was this translation helpful? Give feedback.
-
For anyone stumbling upon this answer nowadays. For later versions of In other words the configs above would need to change to // .storybook/main.js
const path = require('path')
module.exports = {
stories: [
'../src/**/*.stories.mdx',
'../src/**/*.stories.@(js|jsx|ts|tsx)'
],
addons: [
'@storybook/addon-links',
'@storybook/addon-essentials',
'@storybook/preset-create-react-app',
],
webpackFinal: async (config) => {
config.module.rules.push({
test: /\.css$/,
use: [
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
},
},
},
],
include: path.resolve(__dirname, '../'),
})
return config
},
} |
Beta Was this translation helpful? Give feedback.
Hey @nivekithan I believe I answered you on Stackoveflow but I'll put the answer here so it can help others as well!
You're almost there.
The missing piece of your config is to add a webpack configuration to apply tailwind to postcss-loader: