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

CSS variable is removed despite being used in content #641

Open
MuTsunTsai opened this issue Mar 18, 2021 · 5 comments
Open

CSS variable is removed despite being used in content #641

MuTsunTsai opened this issue Mar 18, 2021 · 5 comments
Labels
Milestone

Comments

@MuTsunTsai
Copy link

@MuTsunTsai MuTsunTsai commented Mar 18, 2021

Describe the bug
I'm trying to purge Bootstrap (v.5 in particular), and in my website I have another CSS file that contains the following rule:

@media (hover: none), (pointer: coarse) {
	.btn-primary:hover:not(:focus):not(.active) {
		background-color: var(--bs-primary);
		border-color: var(--bs-primary);
	}
}

Then I run gulp-purgecss as follows:

let purge = require('gulp-purgecss');

gulp.src('bootstrap.min.css')
    .pipe(purge({
	    content: [...], // glob of my files, including the said CSS file
	    safelist: {
	        standard: [/backdrop/] // for Bootstrap Modal
        },
	    fontFace: true,
	    variables: true
    }))
    ...

But the resulting Bootstrap doesn't keep the variable --bs-primary, and for now I need to add --bs-primary to safelist.variables to make it work correctly.

Expected behavior
I expect any variable that is used in the content will be kept.

Environment (please complete the following information):

  • OS: Windows 10
  • Package gulp-purgecss
  • Version 4.0.2
@MuTsunTsai MuTsunTsai added the bug label Mar 18, 2021
@MuTsunTsai
Copy link
Author

@MuTsunTsai MuTsunTsai commented Mar 25, 2021

Problem persists as of version 4.0.3.

@brunoamaral
Copy link

@brunoamaral brunoamaral commented Apr 26, 2021

I'm having the same issue with bootstrap 5, and it only affects the var(--bs-font-sans-serif) statement. Tried to set safelist: ['--bs-font-sans-serif'], following @MuTsunTsai 's suggestion, but it didn't work.

@MuTsunTsai
Copy link
Author

@MuTsunTsai MuTsunTsai commented Apr 26, 2021

@brunoamaral You need to use the object-syntax safelist, not the simple array syntax. Then add the name of the variable under safelist.variables.

@LucasDemea
Copy link

@LucasDemea LucasDemea commented May 20, 2021

Same problem here with bootstrap 5 gutter variables. Safelisting them doesn't work either.

safelist: {
        variables: ['--bs-gutter-x', '--bs-gutter-y'],
} 

@MuTsunTsai
Copy link
Author

@MuTsunTsai MuTsunTsai commented May 20, 2021

How do you use those variables? Safelisting does work in my case though.

@Ffloriel Ffloriel added this to the 5.0.0 milestone Feb 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants