Referencing other bundles in BundleConfig.cs in ASP.NET MVC4 app
Asked Answered
W

1

7

I am working on an MVC4 application where I'm using WebOptimization to do all of my resource handling (cat and min). I have a few pages which are very similar, but need a few varying styles on a page by page basis.

So, I am trying to reference one bundle (base styles) within another bundle (page specific styles) and I'm not having much luck. Here's what I have in my bundle config:

bundles.Add(new StyleBundle("~/bundles/css/search").Include(
  "~/Content/css/partials/grid-controls.css",
  "~/Content/css/partials/grid.css",
  "~/Content/css/views/search.css"));

bundles.Add(new StyleBundle("~/bundles/css/searchtrees").Include(
  "~/bundles/css/search",
  "~/Content/css/views/search/trees.css"));

On the search trees page I get the trees.css but nothing from the base search CSS bundle.

How can I go about referencing the first bundle in the second? I'm sure there's a way, just not too familiar with bundling yet.

Wolenik answered 10/5, 2013 at 16:0 Comment(6)
I don't think you can include a bundle path in another bundle. This is not supported, I believe.Petrinapetrine
instead add trees.css in the first bundle...In either case, you will get same output after minificationBrotherly
@BhushanFirake I could potentially have a shrubs.css and flowers.css and possibly more. Just seems like things aren't separated nicely enough when I push them all into the same bundle.Wolenik
hey then you can have a forest bundle and add all of this in that bundleBrotherly
@BhushanFirake Haha! True, I could do that. :PWolenik
@Wolenik That will simplify your bundles..Brotherly
E
8

You can reuse the file references instead of referencing another bundle. Something like this:

var baseIncludes = new string [] { "~/Content/css/partials/grid-controls.css", "~/Content/css/partials/grid.css", "~/Content/css/views/search.css" };

// 'base' bundle references the base includes
bundles.Add (new StyleBUndle ("~/bundles/css/search").Include (baseIncludes));

// other bundle references the base includes and some extras
bundles.Add (new StyleBundle ("~/bundles/css/searchtrees").Include(baseIncludes).Include ("~/Content/css/views/search/trees.css"));
Eclampsia answered 28/8, 2013 at 11:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.