Skip to content

Instantly share code, notes, and snippets.

@andrewbranch
Last active December 21, 2015 11:38
Show Gist options
  • Save andrewbranch/6300376 to your computer and use it in GitHub Desktop.
Save andrewbranch/6300376 to your computer and use it in GitHub Desktop.
Bundling with BundleTransformer in ASP.NET MVC. Less files need to have their Build Action set to "Content" in their file properties in order to publish successfully.
using System.Web;
using System.Web.Optimization;
using BundleTransformer.Core.Transformers;
namespace Project {
public class BundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
var styles = new Bundle("~/bundles/stylesheets")
.Include(
"~/Assets/stylesheets/*.css",
"~/Assets/stylesheets/*.less"
);
styles.Transforms.Add(new CssTransformer());
bundles.Add(new ScriptBundle("~/bundles/javascripts").IncludeDirectory("~/Assets/javascripts/plugins", "*.js").IncludeDirectory("~/Assets/javascripts", "*.js"));
bundles.Add(styles);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
namespace Project {
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start() {
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
<%= Styles.Render("~/bundles/stylesheets") %>
<%= Scripts.Render("~/bundles/javascripts") %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment