Bundle and Minify functionality not working on Enterprise Visual Studio

Onyango, David 21 Reputation points
2024-10-29T20:41:29.8766667+00:00

I am unable to minify my css and js files in a visual studio c# .net core web app project. I am also unable to launch the minify context menu on against a target file.

I have installed BundlerMinifier.Core nuget package version 3.2.449 but it is not working.

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,684 questions
{count} votes

Accepted answer
  1. JasonPan - MSFT 5,996 Reputation points Microsoft Vendor
    2024-10-30T06:19:33.6266667+00:00

    Hi @Onyango, David,

    We need to install Bundler & Minifier 2022+. Then we can follow the official introduction to use it.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Jason

    2 people found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. SurferOnWww 3,376 Reputation points
    2024-10-30T05:47:48.7733333+00:00

    (1) Add bundleconfig.json file under project root to specify the files to be minified. Below is an example:

    [
      {
        "outputFileName": "wwwroot/css/site.min.css",
        "inputFiles": [
          "wwwroot/css/site.css"
        ]
      },
      {
        "outputFileName": "wwwroot/js/site.min.js",
        "inputFiles": [
          "wwwroot/js/site.js"
        ],
        "minify": {
          "enabled": true,
          "renameLocals": true
        },
        "sourceMap": false
      }
    ]
    

    (2) Add NuGet Package BuildBundlerMinifier:

    enter image description here

    (3) Rebuild solution / project and confirm that the minified files are created according to the bundleconfig.json:

    enter image description here

    (4) Change the file names in link and script tags accordingly:

    <link rel="stylesheet" href="~/css/site.min.css" asp-append-version="true" />
    <script src="~/js/site.min.js" asp-append-version="true"></script>
    

    Please note that the above will not be done automatically by Visual Studio and you must do manually by yourself.


  2. SurferOnWww 3,376 Reputation points
    2024-10-30T05:48:08.63+00:00

    deleted since duplicated


  3. Himanshu Tripathi 0 Reputation points
    2024-10-31T01:04:26.4433333+00:00

    [

    {

    "outputFileName": "wwwroot/css/site.min.css",
    
    "inputFiles": [
    
      "wwwroot/css/site.css"
    
    ]
    

    },

    {

    "outputFileName": "wwwroot/js/site.min.js",
    
    "inputFiles": [
    
      "wwwroot/js/site.js"
    
    ],
    
    "minify": {
    
      "enabled": true,
    
      "renameLocals": true
    
    },
    
    "sourceMap": false
    

    }

    ]


  4. Himanshu Tripathi 0 Reputation points
    2024-10-31T03:59:49.6466667+00:00

    "outputFileName": "wwwroot/css/site.min.css",

    "inputFiles": [

    "wwwroot/css/site.css"

    ]


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.