Search code examples
css.net-corebundle

Remove comments in css bundle without minifying the file


Is there a way to remove comments in a CSS bundle under ASP.NET Core MVC without minifiying? This is how my bundleconfig.json file looks like:

[
  // *** CSS Bundles ***
  {
    "outputFileName": "wwwroot/bundles/css/base-bundle.css",
    "inputFiles": [
      "wwwroot/css/font-imports.css",
      "wwwroot/css/src/lib/bootstrap/dist/css/bootstrap.min.css",
      "wwwroot/css/css/styles.css",
      "wwwroot/css/customStyles.css",
      "wwwroot/css/bxslider/jquery.bxslider.css",
      "wwwroot/css/src/lib/bootstrap-social/bootstrap-social.css",
      "wwwroot/css/base.css" 
    ],     
    "minify": {
      "enabled": false,
      "commentMode": "none" //Here is what I though that it would work
    }
  }
]

Each of the referenced files has comments into it. So I want to remove the comments that you are able to see in the browser console but without minifying the file.

I saw that if you set "minify":{ "enabled":true } the comments are removed as expected, but with "minify":{ "enabled":false} the comments are still there.

Am I missing some configuration? Is there a known issue?


Solution

  • yes is possible I find documentation here: https://lore.chuci.info/taurenshaman/json/3108b142d7b44f91bb7500820d44378f

    for JS files

     {
        "outputFileName": "Bundle/dependencies.min.js",
        "inputFiles": [
          "Bundle/dependencies.js"
        ],
        "minify": {
          "enabled": true,
          "preserveImportantComments": false
        }
      }
    

    For CSS files:

    {
        "outputFileName": "Bundle/site.min.css",
        "inputFiles": [
          "Bundle/site.css"
        ],
        "minify": {
          "enabled": true,
          "commentMode": "none"
        }
      }