storybookjs / addon-postcss

This Storybook addon can be used to run the PostCSS preprocessor against your stories.
MIT License
20 stars 22 forks source link

[Bug] [PostCSS 8] Tailwind apply not working in imported css files #20

Open johanvanhelden opened 3 years ago

johanvanhelden commented 3 years ago

Describe the bug

In my main css files I am importing several other css files to keep things clean and organized. However, in Storybook, these imported files are not processed and the Tailwind @apply logic is not ... "applied".

Steps to reproduce the behavior

  1. Clone the following repo: https://github.com/davidzzheng/breeze
  2. Create a custom.css file in the ./src/styles folder
  3. Add the following CSS:
    .custom {
    @apply text-5xl;
    }
  4. Open the ./src/stories/Playground.stories.tsx story and add the custom class to the div so it will look like this:
    
    export default {
    title: "Playground",
    };

const Template = () => (

Hello World

);

export const Base = Template.bind({});

5. Add the import to the `./src/styles/taildwind.css` file:
```css
@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
    @import './custom.css';
}
  1. npm run storybook
  2. See that the "Hello world" text inside the Playground story is not the size that text-5xl should be.
  3. To ensure the import is working, manually add font-size: 33px and you will see that the text is huge. So the import is fine.
  4. To ensure Tailwind works, place the custom css with the apply right inside the main tailwind.css and notice it also works!

So it only seems a problem inside included css files.

If I compile the css using Laravel Mix it does properly parse and @apply the css. So it really seems to be a Storybook issue.

Expected behavior

The proper css should be @apply'd in included css files.

System

Environment Info:

  System:
    OS: Linux 5.4 Ubuntu 20.04.1 LTS (Focal Fossa)
    CPU: (16) x64 Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz
  Binaries:
    Node: 14.13.0 - ~/.nvm/versions/node/v14.13.0/bin/node
    Yarn: 1.22.5 - /usr/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.13.0/bin/npm
  Browsers:
    Chrome: 89.0.4389.82
  npmPackages:
    @storybook/addon-essentials: ^6.2.7 => 6.2.7
    @storybook/addon-postcss: ^2.0.0 => 2.0.0
    @storybook/builder-webpack5: ^6.2.7 => 6.2.7
    @storybook/vue: ^6.2.7 => 6.2.7
d8vjork commented 3 years ago

Also cannot get Tailwind 2.1+ working with this as our project also requires PostCSS 8

We wanted to move to Vue 3 with Storybook but that is actually impossible

Edit: Related to #19

blowsie commented 3 years ago

I can confirm I also have this issue, using tailwind 1.9.6 and postcss 7

blowsie commented 3 years ago

I think this is because of https://github.com/storybookjs/addon-postcss/issues/10 & https://github.com/storybookjs/addon-postcss/issues/14

johanvanhelden commented 3 years ago

Maybe a stupid question, but what is CRA (as mentioned in https://github.com/storybookjs/addon-postcss/issues/14)? Because I am using Storybook 6.2. So that should not be an issue.

blowsie commented 3 years ago

CreateReactApp I assume

johanvanhelden commented 3 years ago

Hmm, ok. I am using Vue, so I don't that is not really applicable here.

Nexum commented 3 years ago

I can't seem to figure this out, any idea why this happens?

Joralf commented 3 years ago

Any update on PR #19 in relation to this bug?

blowsie commented 3 years ago

@Nexum its detailed in #14 i think

Before Storybook 6.2, it used to install additional loaders on .css and that causes this to crash. In the same way, CRA already had postcss and other loaders on the .css extension that crash this.

charkour commented 2 years ago

I am experiencing this as well with tailwind 2.2.2 and posts 8.3.5

larswaccen commented 2 years ago

I am having the same issue with postcss7 compat. Tailwind works, but not @apply with vue component styles.

info => Using PostCSS preset with postcss@7.0.39 info => Using default Webpack4 setup

... then;

ERROR in ./src/components/N... You may need an additional loader to handle the result of these loaders.

> .nav-icon { | @apply h-6 w-6 text-green mr-2; | }

this is in vue3 with