grunt-contrib-cssmin - how to remove comments from minified css
Asked Answered
G

2

13

Im using cssmin to minify css files.

my config like this:

module.exports = function(grunt) {

    grunt.config.set('cssmin', {
        site: {
            src: ['.tmp/public/concat/site.css'],
            dest: '.tmp/public/min/site.min.css'
        }
    });

    grunt.loadNpmTasks('grunt-contrib-cssmin');
};

But output minified css files has comments. Is it possible to configure cssmin to remove comment from source css files?

Thank you.

Giddy answered 7/1, 2015 at 18:3 Comment(1)
How I can see, this functionality not provided in cssmin - github.com/gruntjs/grunt-contrib-cssmin/blob/master/tasks/…Giddy
T
36

Set keepSpecialComments to zero, for removing all comments.

grunt.config.set('cssmin', {
    options: {
        keepSpecialComments: 0
    },
    site: {
        src: ['.tmp/public/concat/site.css'],
        dest: '.tmp/public/min/site.min.css'
    }
});

For future reference: grunt-contrib-cssmin uses clean-css options.

Tapestry answered 7/1, 2015 at 18:25 Comment(1)
According to the site, the option was renamed to "specialComments" in 4.0.0, but neither specialComments:0 nor keepSpecialComments:0 seem to work.Colossal
C
5

It's an old question but now you can use it like this:

module.exports = function(grunt) {
  grunt.config.set('cssmin', {
    options: {
      level: {
        1: {
          specialComments: 0
        }
      }
    },
    site: {
      src: ['.tmp/public/concat/site.css'],
      dest: '.tmp/public/min/site.min.css'
    }
  });
  grunt.loadNpmTasks('grunt-contrib-cssmin');
};

clean-css #How to apply level 1 & 2 optimizations at the same time?

Cube answered 30/8, 2017 at 12:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.