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

added ability to exclude current rule with an ignore comment placed in… #210

Merged
merged 2 commits into from Oct 6, 2019

Conversation

n1kk
Copy link
Contributor

@n1kk n1kk commented Aug 14, 2019

Proposed changes

Added a feature to ignore current class with a comment /* purgecss ignore current */ inside of it.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

PR to docs: FullHuman/purgecss-docs#33

Further comments

At my current project we use postcss together with scss and the problem arises when we need to ignore lists of generated classes that will be used dynamically. There's to much to keep them in the whitelist or regexp patterns array and it gets problematic to maintain it, and existing ignore comments do not really cover our case easily.

If we use /* purgecss ignore */ before generated class then it doesn't work since the comment is left in the body of parent class:

.parent {
	/* ... */
	@for $i from 1 through $max-size {
		/* purgecss ignore */
		&.size-#{$i} {
			/* ... */
		}
	}
}

turns to

.parent {
	/* ... */

	/* purgecss ignore */
	/* purgecss ignore */
	/* purgecss ignore */
}

.parent .size-1 { /* ... */ }
.parent .size-2 { /* ... */ }
.parent .size-3 { /* ... */ }

And we can't really use ignore start and end comments because scss files have all classes nested under one parent so the whole file will be ignored. We want to ignore only lists that are used dynamically and there is no code reference to them.

Adding comment for ignoring current class easily fixes the issue and doesn't require any list maintaining. If style files are gone no dead code is left behind.

# Conflicts:
#	lib/purgecss.es.js
#	lib/purgecss.js
@n1kk n1kk changed the title added ability to exclude current rule with a ignore comment placed in… added ability to exclude current rule with an ignore comment placed in… Sep 27, 2019
@Ffloriel Ffloriel merged commit d08ca7e into FullHuman:master Oct 6, 2019
Ffloriel added a commit to FullHuman/purgecss-docs that referenced this pull request Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants