Search code examples
asp.netasp.net-mvcoptimizationbundle

How to ignore a specific bundle for optimization in asp.net BundleConfig


public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
                "~/Scripts/jquery-{version}.js"));

    bundles.Add(new ScriptBundle("~/bundles/angularJs").Include(
              "~/Scripts/angular.min.js"));

    bundles.Add(new ScriptBundle("~/bundles/angularComponents").Include(
                "~/Scripts/angular-route.min.js",
                "~/Scripts/angular-local-storage.min.js",
                "~/Scripts/loading-bar.min.js"));


    bundles.Add(new StyleBundle("~/Content/css").Include(
              "~/Content/bootstrap.min.css",
              "~/Content/loading-bar.min.css",
              "~/Content/font-awesome.min.css",
              "~/Content/site.css"));

    bundles.IgnoreList.Clear();
    bundles.IgnoreList.Ignore("*angular-route.min.js", OptimizationMode.Always);
    bundles.IgnoreList.Ignore("*angular-local-storage.min.js", OptimizationMode.Always);
    bundles.IgnoreList.Ignore("*loading-bar.min.js", OptimizationMode.Always);

    BundleTable.EnableOptimizations = true;
}

Here i want to remove this bundle (new ScriptBundle("~/bundles/angularComponents")) from optimization. I have tried the above way, but it doesn't ignore from optimization. Files are combined as well. Can anybody tell me how can i ignore this specific bundle list ?


Solution

  • You can try the bellow code.It will add the related script but do not minify.

    var angularComponents = new ScriptBundle("~/bundles/angularComponents").Include(
                     "~/Scripts/angular-route.min.js",
                     "~/Scripts/angular-local-storage.min.js",
                     "~/Scripts/loading-bar.min.js"
                    );
    
                bundles.Add(angularComponents);
    
                angularComponents.Transforms.Clear();