Tailwind 3 JIT mode does not seem to work with Storybook and @storybook/addon-postcss #6570
Replies: 6 comments 16 replies
-
I was having the same issue until I noticed that in the browser console it said:
The solution was to add this to the if (module.hot) {
module.hot.accept();
} Although I'm not sure if this is the optimal solution, let me know if you find a better one! |
Beta Was this translation helpful? Give feedback.
-
bump as well. |
Beta Was this translation helpful? Give feedback.
-
Hey I finally got it to work. Please see my SO link below and let me know if it works for you! |
Beta Was this translation helpful? Give feedback.
-
I believe I have found a working configuration, with the help of this comment storybookjs/storybook#13538 (comment). The following will enable so Tailwind generate CSS as new tailwind classes are added to the markup in dev mode (hot reload). In summary, I don't think @storybook/addon-postcss works with Tailwind JIT and Storybook hot reload, and the workaround is to use the Install these deps:
// .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/addon-interactions",
// {
// name: "@storybook/addon-postcss",
// options: {
// postcssLoaderOptions: {
// implementation: require("postcss"),
// },
// },
// },
],
framework: "@storybook/react",
core: {
builder: "webpack5",
},
webpackFinal: (config) => {
config.module.rules.push({
test: /\.css$/,
use: [
{
loader: "postcss-loader",
options: {
postcssOptions: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
},
],
include: path.resolve(__dirname, "../"),
});
return config;
},
}; // .storybook/preview.js
import "../styles/globals.css";
export const parameters = {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/,
},
},
}; // postcss.config.js
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}; |
Beta Was this translation helpful? Give feedback.
-
If anyone is having issues (like I was)... Following the official guide works out of the box: https://storybook.js.org/recipes/tailwindcss and seems to be the simplest option (least configuration). |
Beta Was this translation helpful? Give feedback.
-
Hi,
we've just updated to Tailwind 3 and are using it in our Storybook configuration with PostCSS.
Everything seems to work fine, however the CSS doesn't update "just-in-time" when we add new classes to our markup. If we want the watcher update the CSS, we have to manually save our CSS file in order for the watcher to rebuild the CSS.
Any ideas why this happens? Storybook uses Webpack 4 under the hood.
Extract from
package.json
:Storybook's
main.js
(configures PostCSS options):Thanks!
Nik
Beta Was this translation helpful? Give feedback.
All reactions