Search code examples
asp.netasp.net-mvc-4bundling-and-minificationasp.net-optimization

Rendering DynamicFolderBundle?


I'm trying to add a bundled folder so I don't have to manually add each new .less file to the usual bundles, but I don't know how to render it out.

In the BundleConfig,

 BundleTable.Bundles.Add(new DynamicFolderBundle("Content/autobundled", "*.less", new LessTransform(), new CssMinify()));
//.less sheets are at Content/autobundled/example.less 

In the Razor page:

 @Styles.Render("Content/autobundled")

Output:

<link href="/Binky.Web/Content/autobundled" rel="stylesheet">

But that doesn't link any files, just links to the directory which isn't browsable. The articles I read don't say anything about how to use the folder bundles after you create them.


Solution

  • Found the answer here

    Basically create the bundle, where the first parameter is the name (not the path) for the bundle,

    bundles.Add(new DynamicFolderBundle("less", "*.less", new LessMinify()));
    

    And render them by choosing a path, and use the bundle name appended to the path to say, "get all the files specified in this named bundle from this path".

    @Styles.Render("~/Content/autobundled/less")