gulp uncss - ignore via regex won´t work

267 views Asked by At

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.

1

There are 1 answers

3
Mark On BEST ANSWER

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-.*/