Skip to content

Minification breaks nested @apply #14092

Closed
@pokonski

Description

@pokonski

What version of Tailwind CSS are you using?

For example: v3.4.7

What build tool (or framework if it abstracts the build tool) are you using?

tailwindcss standalone executable 3.4.7

What version of Node.js are you using?

N/A, using standalone

What browser are you using?

Firefox 127

What operating system are you using?

MacOS

Reproduction URL

https://github.com/pokonski/tailwind-minify-nesting/tree/master

Describe your issue

Minification breaks nested rules and flattens them:

Source file

.parent {
  & .child {
    @apply text-blue-500;

    &:not([href]) {
      @apply text-red-500;
    }
  }
}

Running tailwindcss -i source.css -o build.css outputs working CSS:

.parent {
  & .child {
    --tw-text-opacity: 1;
    color: rgb(59 130 246 / var(--tw-text-opacity))
  }
  & .child {
    &:not([href]) {
      --tw-text-opacity: 1;
      color: rgb(239 68 68 / var(--tw-text-opacity))
    }
  }
}

But running tailwindcss -i source.css -o build-min.css -m outputs broken CSS with missing nested rules:
(formatted by me for readability)

.parent {
  & .child {
    --tw-text-opacity: 1;
    color: rgb(239 68 68/var(--tw-text-opacity));
    color: rgb(59 130 246/var(--tw-text-opacity))
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions