Gulp minifyCss remove special comments
Asked Answered
P

2

15

I am using gulp minifyCss to minify my css to reduce filesize. My gulp task looks something like this:

gulp.task('minify-css', function() {
  return gulp.src('styles/*.css')
    .pipe(concatCss("all.css").on('error', standardHandler))
    .pipe(minifyCss().on('error', standardHandler))
    .pipe(gulp.dest('dist'));
});

It works fine and output as expected. However, it does not remove special comments /*! comment */

How can I get minifyCss to have special comments removed?

Preterit answered 12/8, 2015 at 8:12 Comment(1)
Just an FYI gulp-minify-css has been deprecated in favor of gulp-clean-cssMessier
H
16

You should set keepSpecialComments option:

gulp.task('minify-css', function() {
  return gulp.src('styles/*.css')
    .pipe(concatCss("all.css").on('error', standardHandler))
    .pipe(minifyCss({keepSpecialComments : 0}).on('error', standardHandler))
    .pipe(gulp.dest('dist'));
});
Hargis answered 12/8, 2015 at 8:29 Comment(1)
As of 4.0 (clean-css), keepSpecialComments has been renamed to just: specialCommentsDough
G
1

Now Ufuk's variant not working. Try this:

.pipe(cleanCSS({level: {1: {specialComments: false}}}))
Guidance answered 28/4, 2018 at 10:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.