ironic
ironic

Reputation: 8949

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")
    );

Upvotes: 9

Views: 1249

Answers (1)

Mihai Dinculescu
Mihai Dinculescu

Reputation: 20033

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*"));

Upvotes: 13

Related Questions