Skip to content

Add an option to prevent removal of unused CSS selectors/classes  #5804

@brgrz

Description

@brgrz

Is your feature request related to a problem? Please describe.

In general, removal of unused CSS is a good thing. From time to time I'd like to opt out of it, for example I'm trying to style <svg> tags which are not yet present in the markup (lazy loaded with fetch). Svelte removes the styles for svg selector since no markup yet exists.

Describe the solution you'd like

Ideally something like :global for example :keep.

:keep(.icon svg) {
  width: 50%;
  height: 50%;
}

There's actually already a workaround and that is to use the :global selector from svelte-preprocess and if I use it with the styles that I don't want removed it works fine. Obviously, with a side effect of moving the targeted styles to root, which is unwanted.

I'd just like to have an option to prevent unused styles optimization occasionally.

Describe alternatives you've considered

The forementioned :global workaround.

How important is this feature to you?

not super crucial at the moment but would be nice to have

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