Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nested bundles in ASP.NET MVC

Is it possible to include one bundle in another bundle in ASP.NET MVC?

I would like to do something like:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include("~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery-ui").Include("~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include("~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/knockout").Include("~/Scripts/knockout-{version}.js").Include("~/Scripts/knockout.ext.js"));
bundles.Add(
    new ScriptBundle("~/bundles/ui")
    .Include("~/bundles/jquery")
    .Include("~/bundles/jquery-ui")
    .Include("~/bundles/jqueryval")
    .Include("~/bundles/knockout")
    );
like image 440
ironic Avatar asked Dec 15 '14 15:12

ironic


1 Answers

You can define the common parts in a string array

string[] jQuery = new string[] { "~/Scripts/jquery-{version}.js", 
                                 "~/Scripts/jquery-ui-{version}.js" };

Then reuse it like this

bundles.Add(new ScriptBundle("~/bundles/jQuery")
    .Include(jQuery));

bundles.Add(new ScriptBundle("~/bundles/jQueryVal")
    .Include(jQuery)
    .Include("~/Scripts/jquery.validate*"));
like image 164
Mihai Dinculescu Avatar answered Nov 02 '22 23:11

Mihai Dinculescu