gulp uncss unexpectedly removing some "ignored" classes

374 Views Asked by At

I'm using gulp uncss. This is my task code:

gulp.task('uncss', () => {
  return gulp.src($uncss.src)
    .pipe(uncss({
        html: JSON.parse(require('fs').readFileSync('./sitemap.json', 'utf-8')),
        ignore: [/\.no-\w+/g, /\.is-\w+/g, /\.plyr\w+/g, /\.lazy\w+/g, /\.\w+\s?\.is-\w+/g]
    }))
    // .pipe(cssnano())
    .on('error', handleErrors)
    .pipe(gulp.dest($uncss.dest))
});

The following line

.is-menu-open .menu__btn span:before, .is-menu-open .menu__btn span:after {
  background-color: #000;
}

is compiled as, once I've run the code through the gulp task above.

.is-menu-open .menu__btn span:before {
  background-color: #000;
}

Any thoughts, my regex skills are some what lacking!

Essentially I need to ignore any classes with .is- anywhere in the selector.

1

There are 1 best solutions below

1
On

According to documentation:

Regular expressions for the ignore and ignoreSheets options should be wrapped in quotation marks.

{"ignore": [ ".unused", "/^#js/" ]}