Monday, 5 August 2013

Adding typescript minified scripts into bundles.

Problem:

I want to add TypeScript generated minified files into bundle configuration.

By default, minified files are excluded.


Solution:
I need to add custom implementation of ignore list in order to manage ignore list. I do not change any configuration of typescripts generated files, but add custom code.

See implementation below:


 protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }

public class BundleConfig
    {

   public static void AddDefaultIgnorePatterns(IgnoreList ignoreList)
        {
            ignoreList.Clear();
            ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
        }

        // For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
        public static void RegisterBundles(BundleCollection bundles)
        {
            AddDefaultIgnorePatterns(bundles.IgnoreList);

            bundles.Add(new ScriptBundle("~/bundles/site")
                .Include("~/Scripts/Site.min.js",
                         "~/Scripts/Test2.min.js"));
        }
}