Gulp minify-css output comments in scss files

I try to be a good boy and minimize my css with gulp. I am currently using gulp -sass (not gulp -ruby-sass) and it doesn't seem to have been built into minifying it. So now I use gulp -minify-css to pass some minification to my compilation. The problem is that now it removes all my comments. like /*comment*/ and //comment . This is not ideal as I need the original comment to customize the wordpress theme.

So, I looked through the documentation ( https://github.com/jonathanepollack/gulp-minify-css/wiki ) and it looks like there is an option for this type of keepSpecialComments.

So, I tried the following in my gulpfile:

 .pipe(minifycss({keepSpecialComments: '*'})) 

and

 .pipe(minifycss({keepSpecialComments: *})) 

The first still crosses out comments. the second reports an error. So I think that I can make a mistake in formatting?

Can someone help me here?

thanks

+6
source share
1 answer

In the second example that you have, there is an asterisk * sitting in the open state - this is not a string. This is why it reports an error.

The docs indicate that the default is to save all special comments. If you go to clean-css , you will see that special comments refer to comments that have an exclamation mark ( ! ) To indicate that they are important . Try changing your comment to look like this, and I'm sure it will save it without any configuration.

 /*! put your settings here */ 

If Wordpress is unable to work with the special comment, for some reason you can use gulp-replace to fix the comment before saving it, for example:

 var replace = require('gulp-replace'); // ... sass, compress-css, etc ... .pipe(replace('/*!', '/*')) // ... gulp.dest, etc ... 

This will remove the exclamation mark from the comment. I would not do it if Wordpress did not work.

+16
source

All Articles