0

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.

magicspon
  • 926
  • 2
  • 9
  • 28
  • I have a feeling `uncss` isn't catching the global flag of the regexs, as `/\.is-\w+/g` should catch that. Does specifying the whole class `.is-menu-open` work? Also, would inline ignoring (on the css) work for you? like so: `/* uncss:ignore */` – HNeiva Sep 27 '16 at 15:20
  • I was testing the expressions on https://regex101.com/ and they were matching as expected. I did not know about `/* uncss:ignore */` , i'll give that a whirl.. Thanks – magicspon Sep 27 '16 at 15:26

1 Answers1

1

According to documentation:

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

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

HNeiva
  • 96
  • 5
  • Example you provided is only if using `uncssrc` option to load options from json file. This is not the case if using `ignore` option. – IVN Oct 07 '16 at 11:36