2

I have been developing on the front end for years but I am finally making the move towards developing using Grunt and moving away from tools like Prepros and Koala for my Sass compilation.

My main question is, how do I force my grunt tasks to remove all comments from the compiled and minified CSS generated from my SASS files?

Currently I have the following gruntfile.js file snippet setup but this only removes single line comments. I want all of my compiled css to be in one big line with no spacing and no comments:

grunt.initConfig({
     pkg: grunt.file.readJSON('package.json'),
     sass: {
       dist:{
           files: {
                'css/main.css' : 'css/main.scss'
           },
           options: {
               style: 'compressed'
           }
       }
     }

})

Any help would be greatly appreciated.

jezzipin
  • 4,110
  • 14
  • 50
  • 94
  • Using the "compressed" output option for Sass should already do what you're asking for. – cimmanon Dec 01 '15 at 14:05
  • 1
    It doesn't. It keeps all multi-line comments. I basically want to remove library comments that come from things like bootstrap. – jezzipin Dec 03 '15 at 10:20

1 Answers1

1

Not sure that grunt-sass plugin can do this job, but grunt-contrib-cssmin yes.

Set keepSpecialComments option to 0 to remove all comments.

From cleancss documentation :

keepSpecialComments - * for keeping all (default), 1 for keeping first one only, 0 for removing all

Simple example :

cssmin: {
  options: {
      keepSpecialComments: 0 
  },
  target: {
    files: {
      'output.css': ['foo.css', 'bar.css']
    }
  }
}
Louis Barranqueiro
  • 10,058
  • 6
  • 42
  • 52