How to filter or extract specific CSS ruleset from a .css file and put it in a separate file

Viewed 27

Is it possible to extract or filter some specific CSS ruleset from a .css file using webpack (using plugin perhaps) or nodejs, and put it in a separate file (fs node)? If yes how?

e.g.

I want to extract .my_class1 ruleset from all.css and put it in separate file extracted.css

Before Extraction

/* all.css */

.my_class1 {
  color: red;
  background: red;
}


.my_class2 {
  color: green;
  background: green;
}

.my_class3 {
  color: blue;
  background: blue;
}

After Extraction

/* all.css */

.my_class2 {
  color: green;
  background: green;
}

.my_class3 {
  color: blue;
  background: blue;
}
/* extracted.css */

.my_class1 {
  color: red;
  background: red;
}
0 Answers
Related