AngularTemplates.Compile

ASP.NET MVC bundle and MsBuild task that combine multiple AngularJS templates into one file.


Keywords
angularjs, msbuild, templates, bundling, System.Web.Optimization
License
MIT
Install
Install-Package AngularTemplates.Compile -Version 1.2.1

Documentation

AngularTemplates.Compile

ASP.NET MVC bundle and MsBuild Task to combine multiple Angular JS templates into a single javascript file. $templateCache angular service is used to cache templates.

Supported platforms:

  • .NET 4.0+
  • Mono 3.8+

Install

PM> Install-Package AngularTemplates.Compile

Options

Prefix - String to prefix template urls with.

ModuleName - AngularJS module name. If not specified defaults to app.

Standalone - Boolean indicated if the templates are part of an existing module or a standalone. Defaults to false. If the value is false, the module will look like angular.module('app'), otherwise angular.module('app', []).

WorkingDir - Working directory to locate templates in.

LowercaseTemplateName - Boolean that indicates if template names (urls) need to be lowercased or not. Defaults to false.

OutputPath - Output path of the compiled JS.

Bundling example

Specify in BundleConfig.cs the following bundle with options:

var options = new TemplateCompilerOptions
    {
        ModuleName = "myapp",
        Prefix = "/",
        Standalone = true
    };

var bundle = new TemplateBundle("~/templates", options)
    .Include("~/templates/template1.html", "~/templates/template2.html");
bundles.Add(bundle);

In your view render this bundle:

@Scripts.Render("~/templates")

MsBuild example

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/MsBuild/2003" DefaultTargets="BuildBundles">
  <UsingTask TaskName="AngularTemplates.Compile.AngularTemplatesTask"
    AssemblyFile="..\packages\AngularTemplates.Compile.1.0.0\lib\net40\AngularTemplates.Compile.dll" />

  <Target Name="BuildBundles">

    <ItemGroup>
      <Templates Include="$(ProjectDir)Scripts\templates\*.html;"/>
    </ItemGroup>

    <AngularTemplatesTask SourceFiles="@(Templates)"
         OutputFile="$(ProjectDir)Scripts\templates\compiled.js"
         Prefix="/"
         ModuleName="myapp"
         WorkingDir="$(ProjectDir)"
         LowercaseTemplateName="True" />

  </Target>

</Project>