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

Issue with tailwind purge and postcss-nested #2152

Closed
tillkruss opened this issue Aug 9, 2020 · 8 comments
Closed

Issue with tailwind purge and postcss-nested #2152

tillkruss opened this issue Aug 9, 2020 · 8 comments

Comments

@tillkruss
Copy link

tillkruss commented Aug 9, 2020

Prior to the Tailwind purge option this CSS worked and wasn't purged:

.dropdown {
    @apply relative;

    &.is-expanded {
        .dropdown-menu {
            @apply block;
        }
    }
}

Now I need to wrap all &.classname in start ignore blocks.

The JavaScript for that class like like:

el.classList.add('is-expanded');

This works by the way:

.dropdown {
    @apply relative;
}

.dropdown.is-expanded {
    .dropdown-menu {
        @apply block;
    }
}
@adamwathan
Copy link
Member

Can you post a project that reproduces? My gut is to say you should make sure the nesting plugin runs before Tailwind which I bet fixes it.

@tillkruss
Copy link
Author

tillkruss commented Aug 15, 2020

That worked, kinda. Might be worth updating the docs.

[
    require('postcss-import'),
    require('postcss-nested'),
    require('tailwindcss'),
    require('autoprefixer'),
]

However, now the @screen sm directives don't work any longer.

What's the best practice here, not use nesting? Use postcss-nesting?

@adamwathan
Copy link
Member

Use the bubble option to make sure @screen directives are bubbled:

https://github.com/postcss/postcss-nested#bubble

@tillkruss
Copy link
Author

tillkruss commented Aug 24, 2020

This isn't working with either bubble or unwrap and with postcss-nested before or after tailwind.

Either media queries don't do @apply, or nested selectors are ignored.

I ended up not using @apply directives inside @screen as a workaround.

mix.postCss('resources/css/app.css', 'public/assets/css', [
    require('postcss-import'),
    require('postcss-nested')({
        bubble: ['screen'],
    }),
    require('tailwindcss'),
    require('autoprefixer'),
]);

@adamwathan
Copy link
Member

Yeah there's another issue about this now too, bleh. Have to fix a bug in postcss-nested unfortunately.

@adamwathan
Copy link
Member

Here's the open issue that is the same underlying issue:

#2192

@tillkruss
Copy link
Author

Perfect. I'll follow that 👍🏻

@ollyollyollyltd
Copy link

For anyone here from Google, note that the Tailwind docs now recommend using tailwindcss/nesting:

To add support for nested declarations, we recommend our bundled tailwindcss/nesting plugin, which is a PostCSS plugin that wraps postcss-nested or postcss-nesting and acts as a compatibility layer to make sure your nesting plugin of choice properly understands Tailwind’s custom syntax like @apply and @screen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants