[postcss-extract] Extract class selectors only #1166
-
I have been meaning to find a way to extract all class selectors in my project and I stumbled upon postcss-extract plugin. Unfortunately, I was not able to write a query that extracts class selectors only. Any help is appreciated! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Hi @MrHBS, That is something I've been wanting to add for some time. Currently we only support the PostCSS API itself.
But specific values, selectors, media queries, ... can not be targeted. I've been considering something like this : /*
- select all rules
- use the selector parser
- pass in the selector of each rule as an argument to the selector parser
- select all classes
*/
rule::selector-parser(selector) class But there are two use cases that need these kind of extra parsers and a new syntax :
Example of 1 .foo {}
.bar, .baz {}
article {} rule::selector-parser(selector) class This would return Example of 2 .foo { color: green; }
article { color: red; } rule:matches(::selector-parser(selector) class) decl This would return If anyone has good ideas suggestions to express this with selectors that already exist in CSS? For me the switch to a different parser and a different AST (from PostCSS to Selector parser) is similar to switching from regular DOM to pseudo elements. But it is also a bit like switching from light DOM to shadow DOM. So things like Expressing which parser to use could also be an argument : The issues I think are here are :
TL;DR; I want to solve this but I want to get it right :) |
Beta Was this translation helpful? Give feedback.
Hi @MrHBS,
That is something I've been wanting to add for some time.
Currently we only support the PostCSS API itself.
So only these constructs can be filtered and selected :
But specific values, selectors, media queries, ... can not be targeted.
I've been considering something like this :
But there are two use cases that need these kind of extra parsers and a new syntax :