Created
March 18, 2021 01:51
-
-
Save dfee/d2d3b4a70f80e5050cf452abfca39f87 to your computer and use it in GitHub Desktop.
Storybook config for TailwindCss 2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <root>/.storybook/main.js | |
const cssRe = /\.css$/; | |
const removeCssRule = (config) => | |
(config.module.rules = config.module.rules.filter( | |
(rule) => String(rule.test) !== String(cssRe), | |
)); | |
module.exports = { | |
stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"], | |
addons: ["@storybook/addon-links", "@storybook/addon-essentials"], | |
webpackFinal: async (config) => { | |
removeCssRule(config); | |
config.module.rules.push({ | |
test: cssRe, | |
sideEffects: true, | |
use: ["style-loader", "css-loader", "postcss-loader"], | |
}); | |
return config; | |
}, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <root>/postcss.config.js | |
module.exports = { | |
plugins: [ | |
require("postcss-import"), | |
require("tailwindcss"), | |
require("autoprefixer"), | |
], | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <root>/.storybook/preview.js | |
// this is the relevant line! | |
import "../src/styles.css"; | |
export const parameters = { | |
actions: { argTypesRegex: "^on[A-Z].*" }, | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* <root>/src/styles.css */ | |
@tailwind base; | |
@tailwind components; | |
@tailwind utilities; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <root>/tailwind.config.js | |
// shouldn't be relevant, but FYI | |
module.exports = { | |
darkMode: false, // or 'media' or 'class' | |
plugins: [], | |
purge: ["./**/*.tsx"], | |
theme: { | |
extend: {}, | |
}, | |
variants: { | |
extend: { | |
cursor: ["disabled"], | |
}, | |
}, | |
}; |
I had to change my postcss.config.js
to:
module.exports = {
plugins: ["postcss-import", "tailwindcss", "autoprefixer"],
};
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Packages I'm using that are relevant:
Notice, we're not using postcss-loader 5 (due to this issue)