grunt-contrib-cssmin - how to remove comments from minified css

☆樱花仙子☆ 提交于 2019-12-04 16:42:56

问题


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.


回答1:


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.




回答2:


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?



来源:https://stackoverflow.com/questions/27825744/grunt-contrib-cssmin-how-to-remove-comments-from-minified-css

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!