[关闭]
@wangxingkang 2017-06-14T15:45:19.000000Z 字数 1946 阅读 1672

Gulp插件之gulp-angular-templatecache

gulp


目录:


gulp-angular-templatecache

项目地址:gulp-angular-templatecache

在$templateCache中连接并注册AngularJS模板。

安装

例子

gulpfile.js

连接目录所有的.html模板保存到 public/templates.js(默认的文件名字)

  1. var templateCache = require('gulp-angular-templatecache');
  2. gulp.task('default', function() {
  3. return gulp.src('templates/**/*.html')
  4. .pipe(templateCache())
  5. .pipe(gulp.dest('public'))
  6. })

结果(public/templates.js)

  1. angular.module('templates').run([$templateCache,
  2. function($templateCache) {
  3. $templateCache.put('template1.html',
  4. // template1.html content (escaped)
  5. );
  6. $templateCache.put('template2.html',
  7. // template2.html content (escaped)
  8. );
  9. // etc.
  10. };
  11. ])

API

gulp-angular-templatecache(filename, options)

filename - {string} [filename='templates.js']

名字在连接时使用

options

root - {string}

模板的url前缀

module - {string} [module='templates']

angular模块的名字

standalone - {boolean} [standalone=false]

创建一个新的AngularJS模块,而不是使用现有的。

base {string | function} [base=file.base]

覆盖文件基本路径

moduleSystem {string}

包装templateCache模块系统,目前支持系统:RequireJS、Browserify ES6和IIFE

transformUrl {function}

在放入$templateCache之前转换生成的URL

  1. transformUrl: function(url) {
  2. return url.replace(/\.tpl\.html$/, '.html')
  3. }

templateHeader {string} [templateHeader=see below]

覆盖模板头部
var TEMPLATE_HEADER = 'angular.module("<%= module %>"<%= standalone %>).run(["$templateCache", function($templateCache) {';

templateHeader {string} [templateHeader=see below]

覆盖模板主要部分
var TEMPLATE_BODY = '$templateCache.put("<%= url %>","<%= contents %>");';

templateFooter {string} [templateFooter=see below]

覆盖模板页脚
var TEMPLATE_FOOTER = '}])';

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注