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

Feature Request: CSS Rule Annotation for Selective Purging #1310

Open
repalogic opened this issue Dec 29, 2024 · 0 comments
Open

Feature Request: CSS Rule Annotation for Selective Purging #1310

repalogic opened this issue Dec 29, 2024 · 0 comments

Comments

@repalogic
Copy link

Currently, PurgeCSS removes unused CSS by analyzing HTML or template files and stripping out selectors that are not referenced. It is possible in the CSS or by using whitelists to annotate CSS code, which should not be purged. This is however difficult to realize because it requires that the complete code is tested for all potential cases. This makes it nearly impossible to use the tool in large-sized projects.

The problem can be solved by using an opposite approach. By default, the complete CSS code should stay safe. It should be however possible via css selector or CSS annotation to annotate CSS which can be analyzed and purged. This would make it possible in large-sized projects to partially test elements for analysis and if tests are succeeding to enable purgecss for these elements.

Describe the solution you'd like
The solution can be realized similarly to the approach already used in safelisting (https://purgecss.com/safelisting.html). Instead of annotating the elements which are safed, it should however be possible to annotate elements which can be analyzed. This could be done with CSS like this:

/* purgecss analyze */ h1 { color: blue; }

h1 { /* purgecss analyze current */ color: blue; }

As alternative, it would be possible to split the CSS files to more modularized approaches. As soon as SCSS is however used with more complex mixins and functions, this approach is not working very well. The mixins are partially creating a lot of additional CSS code which are inserted in many css selectors and especially at this place purgeCSS could create a real benefit. But it should be only applied to a limited set of selectors and not complete files.

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

No branches or pull requests

1 participant