Search code examples
gulp

Minifying the conditional statement used in the comments of HTML using gulp


I want to minify the following HTML code. I am using the gulp-cleanhtml which works fine for me except the following mentioned criteria:

it does not minify the Styles of HTML conditional statements. Check the below code:

<!--[if gte mso 9]>
<style> 
sup 
   {   
     font-size:100% !important;
   }
</style>
<![endif]-->

Can anyone guide me how to go about? So that I can minify the code within those conditional statements?


Solution

  • gulp-htmlmin should get you there with the following options:

    .pipe(
        htmlmin({
            collapseWhitespace: true,
            minifyCSS: true,
            processConditionalComments: true,
        })
    )
    

    which should result in:

    <!--[if gte mso 9]><style>sup{font-size:100%!important}</style><![endif]-->