JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42184
  • Score
    100M100P100Q70926F
  • License MIT

Converts HTML templates into Angular module(s) which includes them in Angular's $templateCache.

Package Exports

  • gulp-angular-templatecache

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gulp-angular-templatecache) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

gulp-angular-templatecache Build Status

Concatenates and registers AngularJS templates in the $templateCache.

For more information about why this could be useful, please refer to this introduction to $templateCache.

Install

Install with npm

npm install gulp-angular-templatecache --save-dev

Example

var gulp = require('gulp');
var templates = require('gulp-angular-templatecache');

gulp.task('default', function () {
    gulp.src('templates/**/*.html')
        .pipe(templates('templates.js'))
        .pipe(gulp.dest('public/templates'));
});

This concatenates all .html-files in the templates directory and outputs a JavaScript file (templates.js in this case).

The plugin produces spaghetti similar to the lines below.

angular.module("templates", []).run([$templateCache,
  function($templateCache) {
    $templateCache.put("404.html", "<h2>Watthaphuck?!</h2><div class=\"alert alert-danger\"><p>The page you are looking for does not exist. Classic 404, homie!</p></div><img src=\"http://www.reactiongifs.com/wp-content/uploads/2013/10/tom-delonge-wtf1.gif\" class=\"img-responsive\"/>");
    
    // ... and the rest of your templates in a similar fashion
  }
]);

You can then include only the templates.js-file and AngularJS will load and cache them all in only one request. Profit!

API

gulp-angular-templatecache(filename)

filename (required) - Name of the JavaScript file gulp should write to.

License

MIT © Mickel