ASP.NET Core 1.0 – Enable Minification

To enable minification, ensure the following:
1. Config.asax, register the BundlesConfig
protected void Application_Start()

{
         BundlesConfig.RegisterBundles(BundleTable.Bundles);
}

2. BundleConfig.cs, include the scripts and enable optimizations
public static void RegisterBundles(BundleCollection bundles)

{
  bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
    "~/Scripts/jquery-{version}.js"));
BundleTable.EnableOptimizations = true;
}

3. main.html, register the scripts

@section scripts {
       @Scripts.Render("~/bundles/jquery")
}

4. In addition the minification process changes $scope and $q into random variables. Since this does nto tell angular what to inject, the solution is to declare your dependencies wrapped in []:
angular.module("MyApp")

       .controller("MyCtrl", ["$scope", "$q", function($scope, $q) {
  // your code
}])

 

This is just the steps you need to enable minification.

Advertisements

About João Sousa
Senior Software Engineer in .Net (Microsoft Certified MTCS and MCPD). .NET Microsoft MVP 2015

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: