Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
johanvanhelden opened this issue Apr 12, 2021 · 15 comments
Open
Labels
bug Something isn't working

Comments

@johanvanhelden
Copy link

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;
}
  1. 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 = () => (
  <div className="bg-gradient-to-r from-red-100 to-blue-800 custom">Hello World</div>
);

export const Base = Template.bind({});
  1. Add the import to the ./src/styles/taildwind.css file:
@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
@johanvanhelden johanvanhelden added the bug Something isn't working label Apr 12, 2021
@johanvanhelden johanvanhelden changed the title [Bug] Tailwind apply not working in imported css files [Bug] [PostCSS 8] Tailwind apply not working in imported css files Apr 12, 2021
@d8vjork
Copy link

d8vjork commented Apr 13, 2021

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
Copy link

blowsie commented Apr 20, 2021

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

@blowsie
Copy link

blowsie commented Apr 20, 2021

I think this is because of
#10
&
#14

@johanvanhelden
Copy link
Author

Maybe a stupid question, but what is CRA (as mentioned in #14)? Because I am using Storybook 6.2. So that should not be an issue.

@blowsie
Copy link

blowsie commented Apr 20, 2021

CreateReactApp I assume

@johanvanhelden
Copy link
Author

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

@Nexum
Copy link

Nexum commented Apr 29, 2021

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

@Joralf
Copy link

Joralf commented Apr 30, 2021

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

@blowsie
Copy link

blowsie commented May 10, 2021

@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
Copy link

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

@larswaccen
Copy link

larswaccen commented Dec 3, 2021

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 <style scoped lang="postcss" />

@blowsie
Copy link

blowsie commented Apr 11, 2022

I still get this issue in latest storybook, postcss, and tailwind.

package json

    "@antfu/eslint-config": "^0.20.2",
    "@babel/core": "^7.17.9",
    "@etchteam/storybook-addon-status": "^4.2.0",
    "@iconify-json/carbon": "^1.1.3",
    "@storybook/addon-a11y": "^6.5.0-alpha.54",
    "@storybook/addon-actions": "^6.5.0-alpha.54",
    "@storybook/addon-essentials": "^6.5.0-alpha.54",
    "@storybook/addon-links": "^6.5.0-alpha.54",
    "@storybook/addon-notes": "^5.3.21",
    "@storybook/addon-postcss": "^2.0.0",
    "@storybook/addons": "^6.5.0-alpha.54",
    "@storybook/csf-tools": "^6.5.0-alpha.54",
    "@storybook/theming": "^6.5.0-alpha.54",
    "@storybook/vue3": "^6.5.0-alpha.54",
    "@types/node": "^17.0.23",
    "@vitejs/plugin-vue": "^2.2.4",
    "@vue/test-utils": "^2.0.0-rc.19",
    "autoprefixer": "^10.4.4",
    "babel-loader": "^8.2.4",
    "eslint": "^8.13.0",
    "jsdom": "^19.0.0",
    "pnpm": "^6.32.6",
    "postcss": "^8.4.12",
    "tailwindcss": "^3.0.23",
    "typescript": "^4.6.3",
    "unplugin-auto-import": "^0.7.0",
    "unplugin-vue-components": "^0.19.2",
    "vite": "^2.8.6",
    "vitest": "^0.9.3",
    "vue-loader": "^17.0.0",
    "vue-tsc": "^0.34.5"

postcss.config.js

module.exports = {
  plugins: {
    'tailwindcss/nesting': {},
    'tailwindcss': {},
    'autoprefixer': {},
  },
}

.storybook/main.js

module.exports = {
  'stories': [
    '../stories/**/*.stories.@(js|jsx|ts|tsx|mdx)',
    '../src/**/*.stories.@(js|jsx|ts|tsx|mdx)'
  ],
  'addons': [
    '@storybook/addon-essentials',
    '@storybook/addon-links',
    '@storybook/addon-a11y',
    '@storybook/addon-notes',
    '@etchteam/storybook-addon-status',
    {
      name: '@storybook/addon-postcss',
      options: {
        postcssLoaderOptions: {
          implementation: require('postcss'),
          postcssOptions: {
            plugins: [
              require('tailwindcss/nesting')(),
              require('tailwindcss')(),
              require('autoprefixer')(),
            ],
          },
        },
      },
    },
  ],
  'framework': '@storybook/vue3',
}

@damianobarbati
Copy link

Did anybody solve this? Any chance to have the @apply directive work in .css imports?

@ssssct
Copy link

ssssct commented Nov 8, 2022

Did anybody solve this? Any chance to have the @apply directive work in .css imports?

@nvuhung
Copy link

nvuhung commented Mar 15, 2023

I use storybook latest version and @storybook/addon-styling version 0.3.1, but still cannot use import in @layer tailwind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

10 participants