2

I am trying to add uncss for my gulp workflow.

To ignore some classes, which are added via javascript for example, i am declaring these classes with "ignore" (in my case, i am trying to uncss the css from the jquery plugin magnific-popup).

my workflow looks like this and uses regex to match all magnific-popup css:

gulp.task("uncsstask", () => {
gulp.src('original-mfp.css')    
.pipe(uncss({
    html:
    [
        'page.html',
    ],
    ignore: [            
        /\.mfp-*.*/g,
    ]
}))
.pipe(gulp.dest('new'));
});

What happen´s is that the class

.mfp-container

makes it to the new css file, but the class

.mfp-content

does not.

I checked the regex statement with various regex checkers.

Lardo
  • 23
  • 5

1 Answers1

0

Add the 'm' flag to your regexp (otherwise it will stop after the first match):

    /\.mfp-*.*/gm,

and why is that first * there? Do you sometimes have 0 or more than one dash after ".mfp"?

[EDIT] : So after looking more carefully at the documentation it appeared that no regexp flag is necessary and the OP indicated that fixed the problem as well as incorporating my other suggestion that the regexp had an unnecessary * in it. I've edited my answer so this information is now in the body of the answer rather than in the comments only. So use:

/\.mfp-.*/
Mark
  • 143,421
  • 24
  • 428
  • 436
  • Actually, looking at the specs I doubt any flag is necessary. What happens if you try it with no flag in he regexp? If it still doesn't work, I'll need an example snippet of your html that uses both selectors you want ignored. – Mark Sep 11 '17 at 19:10
  • Hello - regexp without flags will do it actually right. Thanks a lot! The correct expression is `/\.mfp-.*/` – Lardo Sep 13 '17 at 13:45
  • I've edited my answer to incorporate these comments into a good answer. Thank you for the accepted answer. – Mark Sep 13 '17 at 18:13