9

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")
    );
1
  • 1
    No. It's not possible. Commented Dec 15, 2014 at 16:07

1 Answer 1

13

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*"));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.